Skip to main content

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/None to 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sloppy_json-0.1.0.tar.gz (28.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sloppy_json-0.1.0-py3-none-any.whl (12.2 kB view details)

Uploaded Python 3

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

Hashes for sloppy_json-0.1.0.tar.gz
Algorithm Hash digest
SHA256 3b92a64d541ec49fea569fa20bd7b4a1af42734eadb941d30ec289c21ea458b5
MD5 3bd7771fcb34d401b625c2da2e246a16
BLAKE2b-256 cff54aae1fb72074efd8972d6aa3ac5ecb8e78639e33b750177ee4416e76bf78

See more details on using hashes here.

Provenance

The following attestation bundles were made for sloppy_json-0.1.0.tar.gz:

Publisher: publish.yml on cemrehancavdar/sloppy-json

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for sloppy_json-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 640d802ba29abbd8c706b75b9e2ace3b07cc06dc6690a0bbf2b1c8ef7cd64dca
MD5 07772331bd575cac57f6765a12038430
BLAKE2b-256 c657f9321c1ad71b2ba1c64e9c0b7cc8b218ebf2b546d3fe6d0784a645dd0a76

See more details on using hashes here.

Provenance

The following attestation bundles were made for sloppy_json-0.1.0-py3-none-any.whl:

Publisher: publish.yml on cemrehancavdar/sloppy-json

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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