Skip to main content

sloppy-json

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

Quick Start

from sloppy_json import parse

# Handles almost any broken JSON (permissive by default)
result = parse("{'name': 'test', 'active': True,}")
# Returns: '{"name": "test", "active": true}'

Usage

from sloppy_json import parse, RecoveryOptions

# Default: permissive parsing (maximum recovery)
result = parse("Here is the JSON: {name: 'test'")  # handles everything

# Strict parsing (standard JSON only)
result = parse('{"key": "value"}', RecoveryOptions(strict=True))

# Custom options
opts = RecoveryOptions(
    allow_single_quotes=True,
    allow_trailing_commas=True,
)
result = parse("{'key': 'value',}", opts)

Features

Feature Example Input Output
Single quotes {'key': 'value'} {"key": "value"}
Unquoted keys {key: "value"} {"key": "value"}
Trailing commas {"a": 1,} {"a": 1}
Missing commas {"a": 1 "b": 2} {"a": 1, "b": 2}
Python literals {"flag": True} {"flag": true}
Truncated JSON {"key": "val {"key": "val"}
Code blocks ```json {"a":1}``` {"a": 1}
Comments {"a": 1} // comment {"a": 1}
JS undefined {"a": undefined} {"a": null}
NaN/Infinity {"a": NaN} {"a": "NaN"}

Auto-detection

Automatically detect what options are needed from sample data:

from sloppy_json import parse, RecoveryOptions

samples = ["{'key': 'value',}", "{name: True}"]
options = RecoveryOptions.detect_from(samples)
# options.allow_single_quotes == True
# options.allow_trailing_commas == True
# options.allow_unquoted_keys == True
# options.convert_python_literals == True

result = parse(new_json, options)

Documentation

Similar Projects

  • sloppy-xml-py - A sloppy XML parser by Armin Ronacher for handling malformed XML. The naming of this project was inspired by sloppy-xml-py.
  • json5 - A JSON extension that allows comments, trailing commas, and unquoted keys.

License

MIT

Metadata

Release files for sloppy-json 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sloppy-json 0.2.0
File Size Uploaded Provenance
sloppy_json-0.2.0.tar.gz 209.5 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for sloppy-json 0.2.0
File Interpreter ABI Platform
sloppy_json-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 221.9 kB

Release files / sloppy_json-0.2.0.tar.gz

Download URL sloppy_json-0.2.0.tar.gz
Size 209.5 kB
Tags Source
SHA-256 checksum
How to use checksums
00b9c98f7a7a63a4c75cff59877807b050ae394bad83d345b9a1d664e6bbccc9
BLAKE2b-256 checksum
How to use checksums
1a7cfb28396552434a5fa0519d6fa9992fb59509df5b1e4f0685401b39de7cec
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 28, 2025.

Transparency log

Release files / sloppy_json-0.2.0-py3-none-any.whl

Download URL sloppy_json-0.2.0-py3-none-any.whl
Size 12.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d07bc8a3be0dce9467c2c6a2b1a6163ae02105bc4c6e218cb69f257d23d754d5
BLAKE2b-256 checksum
How to use checksums
2eda6d90bb38ea139f460b5b095d640ee34a4b7488d1243eb6a7cc343bdee9c5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 28, 2025.

Transparency log

Security for sloppy-json 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for sloppy_json-0.2.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 28, 2025.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page