Skip to main content

json-med

PyPI version CI Python License: MIT

Repair malformed JSON from LLM responses. No required dependencies.


The problem

LLMs routinely return broken JSON:

````json
{'name': 'Alice', 'scores': [98, 87, 92,],
````

`json.loads()` raises. Your pipeline breaks. `json-med` fixes it.

## Install

````bash
pip install json-med
# With Pydantic validation support:
pip install "json-med[pydantic]"
````

## Usage

### `repair()` — returns a valid JSON string

````python
from json-med import repair

raw = """```json
{'name': 'Alice', 'scores': [98, 87, 92,],
```"""

fixed = repair(raw)
# '{"name": "Alice", "scores": [98, 87, 92]}'
```

### `parse()` — repair + Pydantic validation

```python
from pydantic import BaseModel
from json-med import parse

class User(BaseModel):
    name: str
    scores: list[int]

user = parse(raw, User)
# User(name='Alice', scores=[98, 87, 92])
```

## What gets repaired

| Issue | Example input | After repair |
|---|---|---|
| Markdown fences | ` ```json\n{...}\n``` ` | `{...}` |
| Trailing commas | `{"a": 1,}` | `{"a": 1}` |
| Single quotes | `{'k': 'v'}` | `{"k": "v"}` |
| Truncated output | `{"name": "Alice"` | `{"name": "Alice"}` |
| UTF-8 BOM | `\ufeff{"k": 1}` | `{"k": 1}` |

## Error handling

```python
from json-med import repair, RepairError

try:
    result = repair("not json at all")
except RepairError as e:
    print(f"Unrecoverable: {e}")
    print(f"Original input: {e.original}")
```

## Roadmap

- [ ] Streaming partial-JSON parsing
- [ ] Configurable repair strategy pipeline
- [ ] JSON arrays at root level (extended support)
- [ ] Cookbook: OpenAI / Anthropic API integration examples

## Contributing

See [CONTRIBUTING.md](CONTRIBUTING.md). All checks must pass before opening a PR.

## License

MIT — see [LICENSE](LICENSE).

Metadata

Release files for json-med 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for json-med 0.2.0
File Size Uploaded Provenance Actions
json_med-0.2.0.tar.gz 10.7 kB With provenance Details for json_med-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for json-med 0.2.0
File Interpreter ABI Platform Actions
json_med-0.2.0-py3-none-any.whl Python 3 none any Details for json_med-0.2.0-py3-none-any.whl

Total release size: 17.6 kB

Release files / json_med-0.2.0.tar.gz

Download URL json_med-0.2.0.tar.gz
Size 10.7 kB
Tags Source
SHA-256 checksum
How to use checksums
49da3ab9d866cdb1aa2bb850bb79096d1adc349243dd621de344059f9ecefb51
BLAKE2b-256 checksum
How to use checksums
371ece54f3efa8af16d48f28bc1fef965aad1c8ad187e2459f5b7e8564598c09
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 12, 2026.

Transparency log

Release files / json_med-0.2.0-py3-none-any.whl

Download URL json_med-0.2.0-py3-none-any.whl
Size 6.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0c646bd06d01acc3a826bb97177c406bdfee6714af96e748b12150e759b863a6
BLAKE2b-256 checksum
How to use checksums
f8e678f13ac76aabd6219378104f93619e8051b6315b4d08723338f9aa01e7c4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 12, 2026.

Transparency log

Security for json-med 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for json_med-0.2.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 12, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files Full provenance

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