Metadata-Version: 2.4
Name: jsonfix-llm
Version: 0.1.1
Summary: Repair broken JSON from LLM outputs
Author-email: Shashi Kundan <shashikundan0001@gmail.com>
Project-URL: Homepage, https://github.com/shashi3070/jsonfix-llm
Project-URL: Repository, https://github.com/shashi3070/jsonfix-llm
Project-URL: Documentation, https://github.com/shashi3070/jsonfix-llm#readme
Project-URL: Issues, https://github.com/shashi3070/jsonfix-llm/issues
Project-URL: Changelog, https://github.com/shashi3070/jsonfix-llm/blob/main/CHANGELOG.md
Keywords: json,llm,repair,fix,ai,markdown,extraction,parsing,recovery,json-repair
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: Text Processing :: General
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: pydantic>=2.0
Requires-Dist: typer>=0.9
Provides-Extra: dev
Requires-Dist: pytest>=7; extra == "dev"
Requires-Dist: pytest-cov>=4; extra == "dev"
Requires-Dist: ruff>=0.1; extra == "dev"
Dynamic: license-file

# jsonfix-llm

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

## Install

```bash
pip install jsonfix-llm
```

## Quick Start

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

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

```bash
# 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

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

## Publishing to PyPI

### First-time setup

```bash
pip install build twine
```

Create an account at [pypi.org](https://pypi.org) and generate an API token at
https://pypi.org/manage/account/token/.

### First-time publish

```bash
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**:
   ```bash
   python -m build
   twine upload dist/*
   ```
3. **Commit & push**:
   ```bash
   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.
