Metadata-Version: 2.4
Name: json-healer-lite
Version: 0.1.0
Summary: A zero-dependency Python micro-tool to repair and parse malformed, truncated, or markdown-wrapped JSON from LLMs.
Author-email: Encephos <magiltraun@gmail.com>
Project-URL: Homepage, https://github.com/Encephos/json-healer-lite
Keywords: llm,json,repair,heal,streaming,zero-dependency
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Intended Audience :: Developers
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Dynamic: license-file

# json-healer-lite

[![PyPI version](https://img.shields.io/pypi/v/json-healer-lite.svg)](https://pypi.org/project/json-healer-lite/)
[![Python versions](https://img.shields.io/pypi/pyversions/json-healer-lite.svg)](https://pypi.org/project/json-healer-lite/)
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/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
```bash
pip install json-healer-lite
```

## Usage
```python
from json_healer_lite import heal_json, JSONHealerError
```
```json
# 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,
"""
```

```python
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.
