Metadata-Version: 2.4
Name: jsonheal
Version: 0.1.0
Summary: Repair the broken JSON that LLMs return.
Author: episodely
License: MIT
Project-URL: Homepage, https://github.com/episodely/jsonheal
Project-URL: Issues, https://github.com/episodely/jsonheal/issues
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Operating System :: OS Independent
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Dynamic: license-file

# jsonheal

Repair the broken JSON that language models return. Pure Python, no dependencies.

Fixes: markdown code fences and chatter around the JSON, trailing commas, single quotes, unquoted keys, `None`/`True`/`False`, comments, smart quotes, and output that was cut off mid-way (open strings, arrays and objects get closed).

```python
from jsonheal import heal

heal("Sure! ```json\n{'name': 'Ali', tags: ['a', 'b',],}\n```")
# {'name': 'Ali', 'tags': ['a', 'b']}

heal('{"items": [{"id": 1}, {"id": 2')
# {'items': [{'id': 1}, {'id': 2}]}
```

CLI:

```
cat llm_output.txt | python -m jsonheal
```

Valid JSON is returned untouched. If nothing sensible can be recovered it raises `ValueError`. Truncated output is repaired structurally, so check that the data you get back is complete enough for your use.

## Install

```
pip install jsonheal
```

Or copy `jsonheal.py` into your project, it has no dependencies.

## Test

```
python -m pytest
```

MIT licensed.
