Skip to main content

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


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 hashes)

Uploaded Source

Built Distribution

sick_json-0.0.4-py3-none-any.whl (3.3 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page