json-healer-lite
A zero-dependency Python micro-tool to instantly repair and parse malformed, truncated, or markdown-wrapped JSON strings generated by LLMs.
The Problem
When using Large Language Models (LLMs) to generate JSON, you frequently encounter three issues that crash json.loads():
- Markdown Wrappers: The LLM wraps the output in
```json ... ```. - Token Limits / Streaming: The response is cut off mid-generation, leaving unclosed brackets
[{or unclosed strings. - Trailing Commas: The LLM leaves a trailing comma like
{"a": 1, }.
The Solution
json-healer-lite is a pure standard library tool that acts as a robust middle layer. It cleans the string, balances the stack of missing brackets, and safely parses the JSON—saving your API pipelines from crashing.
Installation
pip install json-healer-lite
Usage
from json_healer_lite import heal_json, JSONHealerError
# Typical LLM output that got cut off due to max_tokens:
broken_llm_output = """
{
"status": "success",
"data": [
{"name": "Alice", "score": 95},
{"name": "Bob", "score": 82,
"""
try:
# Heals markdown, trailing commas, and auto-closes the string, dict, and array!
healed_data = heal_json(broken_llm_output)
print(healed_data)
# Output: {'status': 'success', 'data': [{'name': 'Alice', 'score': 95}, {'name': 'Bob', 'score': 82}]}
except JSONHealerError as e:
print(f"JSON was too corrupted to save: {e}")
Why zero-dependency
Frameworks like LangChain provide output parsers, but pulling in a massive dependency tree just to fix a few missing brackets adds latency and bloat (especially in serverless environments like AWS Lambda). This micro-tool operates in under 1ms and weighs just a few kilobytes.
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 json_healer_lite-0.1.0.tar.gz.
File metadata
- Download URL: json_healer_lite-0.1.0.tar.gz
- Upload date:
- Size: 4.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bf28f3cbe6bb0b55a014789c0c573031a6373c75009dbad83037fab90335f649
|
|
| MD5 |
d74a48bedf0ce93c7063d86005bb2806
|
|
| BLAKE2b-256 |
7861cad2b6c929096b0782dc459af519ea87bc9b6905c6f90709d4814e6dfa89
|
Provenance
The following attestation bundles were made for json_healer_lite-0.1.0.tar.gz:
Publisher:
publish.yml on Encephos/json-healer-lite
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
json_healer_lite-0.1.0.tar.gz -
Subject digest:
bf28f3cbe6bb0b55a014789c0c573031a6373c75009dbad83037fab90335f649 - Sigstore transparency entry: 2684485338
- Sigstore integration time:
-
Permalink:
Encephos/json-healer-lite@ac68c00b92f9e32b2168950d073967a05e512615 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/Encephos
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@ac68c00b92f9e32b2168950d073967a05e512615 -
Trigger Event:
release
-
Statement type:
File details
Details for the file json_healer_lite-0.1.0-py3-none-any.whl.
File metadata
- Download URL: json_healer_lite-0.1.0-py3-none-any.whl
- Upload date:
- Size: 4.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
00fcb7463f6ad7d77e7b6a052ad791b3a39303d1dc487bab2e41db00b82e6c21
|
|
| MD5 |
2777950742456b5c3bc1af694f2e3184
|
|
| BLAKE2b-256 |
67c07124b009241ddb871cbe5224daeffca8b694732ece50edade2e330495150
|
Provenance
The following attestation bundles were made for json_healer_lite-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on Encephos/json-healer-lite
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
json_healer_lite-0.1.0-py3-none-any.whl -
Subject digest:
00fcb7463f6ad7d77e7b6a052ad791b3a39303d1dc487bab2e41db00b82e6c21 - Sigstore transparency entry: 2684485392
- Sigstore integration time:
-
Permalink:
Encephos/json-healer-lite@ac68c00b92f9e32b2168950d073967a05e512615 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/Encephos
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@ac68c00b92f9e32b2168950d073967a05e512615 -
Trigger Event:
release
-
Statement type: