A simple tool to parse the non-normal JSON
The only function implemented in this module is parse.
parse is similar to json.loads. However, it corrects some mistakes that LLM can make.
It can be installed with pip install sick-json and used with import sick_json;sick_json.parse(something).
By default, it uses a JSON5 parser, which solves the following problems.
- Identifiers without quotes
{
name: "Kim"
}
- Trailing comma
{
"name": "Kim",
}
- JS-style comment
{
"name": "Kim" // something
}
Additionally, it heuristically solves a few problems.
- Allow "True" and "False"
{
"name": "Kim",
"is_good_guy": True
}
- Verbose before and after JSON
blah blah blah
{
"name": "Kim"
}
blah blah blah
- If you have multiple JSONs, it will return the longest by default, or you can specify a pydantic format.
import sick_json
from pydantic import BaseModel
maybe_json = 'blah{"name": "Kim"}blah{"names": ["Kim", "Lee"]}blah'
sick_json.parse(maybe_json)
# it return {"names": ["Kim", "Lee"]}
class MyModel(BaseModel):
name: str
sick_json.parse(maybe_json, pydantic_model=MyModel)
# it return {"name": "Kim"}
- Type-correcting by pydantic model
import sick_json
from pydantic import BaseModel
maybe_json = '{"name": "Kim", "age": "13"}'
class MyModel(BaseModel):
name: str
age: int
sick_json.parse(maybe_json, pydantic_model=MyModel)
# it return {"name": "Kim", "age": 13}
Metadata
Release files for sick-json 0.0.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| sick_json-0.0.4.tar.gz | 4.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| sick_json-0.0.4-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 7.4 kB
Release files / sick_json-0.0.4.tar.gz
| Download URL | sick_json-0.0.4.tar.gz |
|---|---|
| Size | 4.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d1362fb83cab70700ea128f8bb70b0c31d9a217280f5051ae6ded9e941d4f8a1
|
|
BLAKE2b-256 checksum How to use checksums |
bccbde66e273324b5227a5f1c167d8721e8e7576429dff717aaf64e5aeeff3f8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.2
|
Release files / sick_json-0.0.4-py3-none-any.whl
| Download URL | sick_json-0.0.4-py3-none-any.whl |
|---|---|
| Size | 3.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
366203935ea05db41d14a9cb299e74457cfada21f0a66a375db6520a875a4bcf
|
|
BLAKE2b-256 checksum How to use checksums |
e15e45fe668da8b9233077b85b084e403bd1880a5f514e11f59931c0fe14cee6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.2
|