Skip to main content

jsonfix-llm

Repair broken JSON from LLM outputs. Stop fighting malformed JSON.

Install

pip install jsonfix-llm

Quick Start

from jsonfix_llm import repair_json

fixed = repair_json("""{
  'name': 'shashi'
  'age': 25
}""")
# {"name": "shashi", "age": 25}

Features

  • Markdown fence stripping — removes ```json ... ``` wrappers
  • Comment stripping — removes // and /* */ comments
  • Quote fixing — single quotes → double quotes, unquoted keys → quoted
  • Literal fixing — True/False/None → true/false/null
  • Comma fixing — inserts missing commas, removes trailing commas
  • Value fixing — fills missing values, fixes missing colons
  • Control char escaping — escapes literal newlines/tabs in strings
  • Bracket auto-close — appends missing } or ], handles truncation
  • Code extraction — extracts code from fenced, indented, inline, and XML blocks
  • CLI tool — quick repair from the terminal

API

from jsonfix_llm import repair_json, extract_code, extract_json

# Simple repair
fixed = repair_json(text)

# Rich result
result = repair_json(text, rich=True)
print(result.fixed)
print(result.was_repaired)
print(result.fixes)
print(result.error_count)
print(result.errors)

# Extract code (default: first Python block)
code = extract_code(text)
# language-specific: extract_code(text, language="python")
# all blocks: extract_code(text, language="json", all=True)

# Extract JSON blocks
json_block = extract_json(text)
json_blocks = extract_json(text, all=True)

CLI

# Repair JSON file
jsonfix broken.json

# Read from stdin
echo '{"a":1' | jsonfix

# Write to file
jsonfix in.json -o fixed.json

# Show repair stats
jsonfix in.json --stats

# Extract code blocks
jsonfix extract file.md --language python
jsonfix extract file.md --language python -o output.py
jsonfix extract file.md --language json --all

Development

pip install -e ".[dev]"
pytest tests/ -v

Publishing to PyPI

First-time setup

pip install build twine

Create an account at pypi.org and generate an API token at https://pypi.org/manage/account/token/.

First-time publish

python -m build
twine upload dist/*
# Username: __token__
# Password: <your-pypi-token>

Bug fix release (patch)

After fixing a bug:

  1. Bump the patch version in pyproject.toml:
    version = "0.1.0"  →  version = "0.1.1"
    
  2. Build & upload:
    python -m build
    twine upload dist/*
    
  3. Commit & push:
    git add -A
    git commit -m "Bump version to 0.1.1"
    git push
    

New feature release (minor / major)

  1. Bump version in pyproject.toml (semver: MAJOR.MINOR.PATCH):
    • New feature: 0.1.0 → 0.2.0
    • Breaking change: 0.1.0 → 1.0.0
  2. Update CHANGELOG.md
  3. Build, upload, commit & push (same steps as above)

Note: PyPI does not allow re-uploading the same version. Always bump before uploading.

Metadata

Release files for jsonfix-llm 0.1.1

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

Source distribution (sdist)

Source distribution for jsonfix-llm 0.1.1
File Size Uploaded Provenance
jsonfix_llm-0.1.1.tar.gz 15.4 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for jsonfix-llm 0.1.1
File Interpreter ABI Platform
jsonfix_llm-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 27.8 kB

Release files / jsonfix_llm-0.1.1.tar.gz

Download URL jsonfix_llm-0.1.1.tar.gz
Size 15.4 kB
Tags Source
SHA-256 checksum
How to use checksums
8935a23ce91fbf1a5221885b7f82a2c1a2e251b3cc2c13ada23637c5392f31ce
BLAKE2b-256 checksum
How to use checksums
beedbb666e76734e69d547fc543b8d781ba7b25e9ed95f1ba800da5f8df49480
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.3

Release files / jsonfix_llm-0.1.1-py3-none-any.whl

Download URL jsonfix_llm-0.1.1-py3-none-any.whl
Size 12.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c6ea3eb16600294d0134b40ad12c6774e4adb4989ea474b560e08fbf92638b18
BLAKE2b-256 checksum
How to use checksums
670d62a1272741608f3202556038e4f43049383fc75d5e9d886b129b96279643
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.3

Security for jsonfix-llm 0.1.1

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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.1.1 This release

2 release files No 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