A forgiving JSON parser that recovers broken JSON from LLM outputs
Project description
sloppy-json
A forgiving JSON parser that recovers broken JSON from LLM outputs.
Installation
uv add sloppy-json
or with pip:
pip install sloppy-json
Usage
from sloppy_json import parse, parse_lenient, parse_permissive, RecoveryOptions
# Strict parsing (standard JSON only)
result = parse('{"key": "value"}')
# Lenient parsing (common LLM issues)
result = parse_lenient("{'key': 'value',}") # single quotes + trailing comma
# Permissive parsing (maximum recovery)
result = parse_permissive("Here is the JSON: {name: 'test'") # everything
# Custom options
opts = RecoveryOptions(
allow_single_quotes=True,
allow_trailing_commas=True,
convert_python_literals=True,
)
result = parse("{'flag': True,}", opts)
Features
- Quoting: Unquoted keys, single-quoted strings
- Commas: Trailing commas, missing commas
- Incomplete JSON: Auto-close objects, arrays, strings
- Extra content: Extract JSON from surrounding text or code blocks
- Python literals: Convert
True/False/Noneto JSON equivalents - Special values: Handle
undefined,NaN,Infinity - Comments: JavaScript-style
//and/* */comments - Escape handling: Handle unescaped newlines in strings
Auto-detection
Automatically detect what options are needed:
from sloppy_json import detect_required_options
samples = ["{'key': 'value',}", "{name: True}"]
options = detect_required_options(samples)
# options.allow_single_quotes == True
# options.allow_trailing_commas == True
# options.allow_unquoted_keys == True
# options.convert_python_literals == True
License
MIT
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sloppy_json-0.1.0.tar.gz.
File metadata
- Download URL: sloppy_json-0.1.0.tar.gz
- Upload date:
- Size: 28.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3b92a64d541ec49fea569fa20bd7b4a1af42734eadb941d30ec289c21ea458b5
|
|
| MD5 |
3bd7771fcb34d401b625c2da2e246a16
|
|
| BLAKE2b-256 |
cff54aae1fb72074efd8972d6aa3ac5ecb8e78639e33b750177ee4416e76bf78
|
Provenance
The following attestation bundles were made for sloppy_json-0.1.0.tar.gz:
Publisher:
publish.yml on cemrehancavdar/sloppy-json
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sloppy_json-0.1.0.tar.gz -
Subject digest:
3b92a64d541ec49fea569fa20bd7b4a1af42734eadb941d30ec289c21ea458b5 - Sigstore transparency entry: 780539034
- Sigstore integration time:
-
Permalink:
cemrehancavdar/sloppy-json@09374e003629b395fc26804ddc351f6b46f582a9 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/cemrehancavdar
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@09374e003629b395fc26804ddc351f6b46f582a9 -
Trigger Event:
release
-
Statement type:
File details
Details for the file sloppy_json-0.1.0-py3-none-any.whl.
File metadata
- Download URL: sloppy_json-0.1.0-py3-none-any.whl
- Upload date:
- Size: 12.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
640d802ba29abbd8c706b75b9e2ace3b07cc06dc6690a0bbf2b1c8ef7cd64dca
|
|
| MD5 |
07772331bd575cac57f6765a12038430
|
|
| BLAKE2b-256 |
c657f9321c1ad71b2ba1c64e9c0b7cc8b218ebf2b546d3fe6d0784a645dd0a76
|
Provenance
The following attestation bundles were made for sloppy_json-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on cemrehancavdar/sloppy-json
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sloppy_json-0.1.0-py3-none-any.whl -
Subject digest:
640d802ba29abbd8c706b75b9e2ace3b07cc06dc6690a0bbf2b1c8ef7cd64dca - Sigstore transparency entry: 780539036
- Sigstore integration time:
-
Permalink:
cemrehancavdar/sloppy-json@09374e003629b395fc26804ddc351f6b46f582a9 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/cemrehancavdar
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@09374e003629b395fc26804ddc351f6b46f582a9 -
Trigger Event:
release
-
Statement type: