A simple tool to parse the non-normal JSON that LLM responds to.
Project description
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}
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
sick_json-0.0.4.tar.gz
(4.1 kB
view details)
Built Distribution
File details
Details for the file sick_json-0.0.4.tar.gz
.
File metadata
- Download URL: sick_json-0.0.4.tar.gz
- Upload date:
- Size: 4.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d1362fb83cab70700ea128f8bb70b0c31d9a217280f5051ae6ded9e941d4f8a1 |
|
MD5 | 6b3ceb8f8671e033df7d44c312f6a58f |
|
BLAKE2b-256 | bccbde66e273324b5227a5f1c167d8721e8e7576429dff717aaf64e5aeeff3f8 |
File details
Details for the file sick_json-0.0.4-py3-none-any.whl
.
File metadata
- Download URL: sick_json-0.0.4-py3-none-any.whl
- Upload date:
- Size: 3.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 366203935ea05db41d14a9cb299e74457cfada21f0a66a375db6520a875a4bcf |
|
MD5 | 0e0cd7dd94a4620923e59bad4f2aeda8 |
|
BLAKE2b-256 | e15e45fe668da8b9233077b85b084e403bd1880a5f514e11f59931c0fe14cee6 |