Skip to main content

json-healer-lite

PyPI version Python versions License: MIT

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():

  1. Markdown Wrappers: The LLM wraps the output in ```json ... ```.
  2. Token Limits / Streaming: The response is cut off mid-generation, leaving unclosed brackets [{ or unclosed strings.
  3. 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

json_healer_lite-0.1.0.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

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

json_healer_lite-0.1.0-py3-none-any.whl (4.4 kB view details)

Uploaded Python 3

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

Hashes for json_healer_lite-0.1.0.tar.gz
Algorithm Hash digest
SHA256 bf28f3cbe6bb0b55a014789c0c573031a6373c75009dbad83037fab90335f649
MD5 d74a48bedf0ce93c7063d86005bb2806
BLAKE2b-256 7861cad2b6c929096b0782dc459af519ea87bc9b6905c6f90709d4814e6dfa89

See more details on using hashes here.

Provenance

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

Publisher: publish.yml on Encephos/json-healer-lite

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

File details

Details for the file json_healer_lite-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for json_healer_lite-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 00fcb7463f6ad7d77e7b6a052ad791b3a39303d1dc487bab2e41db00b82e6c21
MD5 2777950742456b5c3bc1af694f2e3184
BLAKE2b-256 67c07124b009241ddb871cbe5224daeffca8b694732ece50edade2e330495150

See more details on using hashes here.

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

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

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 files

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