repairjson
A small Rust-backed Python library for repairing malformed JSON from language models and other text sources. Recover a value from single quotes, Python literals, missing punctuation, Markdown fences, and truncated containers.
python -m pip install repairjson
import repairjson
source = "{user: 'alice', active: True, tags: ['x', 'y',],}"
print(repairjson.repair(source))
# {"user":"alice","active":true,"tags":["x","y"]}
print(repairjson.loads(source))
# {'user': 'alice', 'active': True, 'tags': ['x', 'y']}
CPython 3.8+ is supported. Binary wheels cover Windows, macOS, glibc Linux, and musl Linux on the release platforms. Installation from a wheel requires no Rust toolchain and adds no Python runtime dependencies. Source builds require Rust 1.88+ and a C linker. PyPy and free-threaded Python wheels are not part of the supported release matrix.
Repair examples
| Input | Repaired JSON |
|---|---|
{name: 'Ada', ready: True} |
{"name":"Ada","ready":true} |
{items: [1 2 3,]} |
{"items":[1,2,3]} |
{count 2} |
{"count":2} |
{missing:, next: 2} |
{"missing":null,"next":2} |
{items: [1, 2 |
{"items":[1,2]} |
{value: +.5, other: 01, exp: 1e+} |
{"value":0.5,"other":1,"exp":1e+0} |
Here is the result: {ok: True} |
{"ok":true} |
Quoted Unicode and JSON escapes are preserved. Raw control characters inside strings are escaped, including carriage returns and NUL bytes. Unquoted Unicode keys and values are accepted. See repair rules and boundaries for exact examples and ambiguous cases.
API
| Name | Result |
|---|---|
repair(input: str) -> str |
One compact JSON value as text |
loads(input: str) -> Any |
The repaired value decoded by Python's json.loads() |
repair_to_string(input: str) -> str |
Compatibility alias for repair() |
repair_json(input: str) -> str |
Compatibility alias for repair() |
__version__ |
Installed package version |
MAX_DEPTH |
Maximum nesting: 128 simultaneously open containers |
All functions accept a Python str. Empty input becomes null (None with loads). More than 128 nested objects/arrays raises ValueError. Ambiguous unescaped quotes in an object value also raise ValueError (for example, {"command": "say "hello" now"}). Escape the inner quotes before retrying. Non-string inputs raise TypeError. Raw unpaired surrogates cannot cross the UTF-8 extension boundary and raise UnicodeError; escaped forms such as r'"\ud800"' are accepted. loads also inherits Python's numeric conversion limits and errors.
The Rust repair step releases the GIL. Each call owns its parser state, so independent inputs can be repaired from multiple Python threads. Type stubs and a py.typed marker are included.
Choosing a repair policy
Repair is heuristic: it produces a plausible value, not proof of the source's intended meaning. Validate the result against your application's expected schema. This is useful for recovering a model's response; it is not a substitute for strict parsing when accepting configuration, authorizations, or signed data.
- The first object or array outside quotes takes precedence over a prose preamble. Otherwise the first scalar is parsed.
- Text after the recovered value is ignored. This is not a JSON Lines or streaming parser.
- A missing closing delimiter is inserted; an encountered parent delimiter ends the nested container. Later text may therefore be excluded.
- Duplicate keys remain in repaired text;
loadskeeps the last value, like Python's JSON decoder. - Line (
//) and block (/* ... */) comments are skipped outside strings. JavaScript expressions and arbitrary multiword bare strings are not supported syntax. - Callers should bound input size. Repair uses memory proportional to input/output size; the nesting limit does not limit large strings or arrays.
The project is alpha software. Version 0.2 improves several repair choices and adds a nesting error; see the migration notes.
Benchmarks
The benchmark harness compares repair-to-string throughput with Python's json-repair. It generates six synthetic corpora of many small records, checks sampled output equivalence, warms both implementations, alternates execution order, and reports repeated timings with environment metadata.
uv venv --python 3.12
uv pip install -e ".[dev,benchmark]"
.venv/bin/python benchmark.py --megabytes 1 --repeat 3 --output benchmarks/local.json
See methodology and a reproducible sample run. These corpora do not measure repair accuracy, large-document latency, or performance on your own model output. No universal speedup is promised.
Development and community
Start with CONTRIBUTING.md for setup, checks, and parser changes. The architecture notes explain the parser and release guide covers publication.
- Report a bug with a minimal, non-sensitive example.
- Request a feature with the input and intended behavior.
- Report security issues privately using the security policy.
- Read the changelog and contributor conduct guidelines.
MIT licensed. See LICENSE.
Metadata
Release files for repairjson 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| repairjson-0.2.0.tar.gz | 34.2 kB | Details |
Built distributions (wheels)
Total release size: 4.3 MB
Release files / repairjson-0.2.0.tar.gz
| Download URL | repairjson-0.2.0.tar.gz |
|---|---|
| Size | 34.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
92a9d7623c30d8707bcc23ada595cf02b217017b10e823fbf338389510bd32ff
|
|
BLAKE2b-256 checksum How to use checksums |
cf8d4a4cfcb81d66570f55b675a268becaf966287da7068069364684b344e503
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Sep 22, 2026.
Transparency logRelease files / repairjson-0.2.0-cp38-abi3-win_arm64.whl
| Download URL | repairjson-0.2.0-cp38-abi3-win_arm64.whl |
|---|---|
| Size | 112.5 kB |
| Tags | CPython 3.8 Windows ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
eca1fcca7831ce503acab36b548af63d74a93a8a4f5d1797c7921dc2ce7dd9f4
|
|
BLAKE2b-256 checksum How to use checksums |
a76aa884619adf83727991b59c744065be868402b0c5ff0a3bb281d7caad01a4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Sep 22, 2026.
Transparency logRelease files / repairjson-0.2.0-cp38-abi3-win_amd64.whl
| Download URL | repairjson-0.2.0-cp38-abi3-win_amd64.whl |
|---|---|
| Size | 112.9 kB |
| Tags | CPython 3.8 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
b4cd5fcc9e05cc225bb080a7458f2e4adfac93f2f1a6b49fe6adb455ca9edbe8
|
|
BLAKE2b-256 checksum How to use checksums |
c75391538127dd749269ab150bda51d13efd3400c8e2a77bfe41c30d355b6e72
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Sep 22, 2026.
Transparency logRelease files / repairjson-0.2.0-cp38-abi3-win32.whl
| Download URL | repairjson-0.2.0-cp38-abi3-win32.whl |
|---|---|
| Size | 107.6 kB |
| Tags | CPython 3.8 Windows x86-32 abi3 |
|
SHA-256 checksum How to use checksums |
f24b57562b6c35ea1820f9ed1ac5fc007c1adecaa75ed129daa5d8d078bc1b5a
|
|
BLAKE2b-256 checksum How to use checksums |
e516cb1cfcf4be032d19dcdb10681434f4aebb09443c4b206a71ceb16efd7bf8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Sep 22, 2026.
Transparency logRelease files / repairjson-0.2.0-cp38-abi3-musllinux_1_2_x86_64.whl
| Download URL | repairjson-0.2.0-cp38-abi3-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 451.8 kB |
| Tags | CPython 3.8 Linux musl 1.2+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
859d415c908a4a0d9f427499773514fc60a9f65fc7b929badf478ef12f1c6398
|
|
BLAKE2b-256 checksum How to use checksums |
0cd7d43755d5ab6aeb47e483b3fee156fc1bcc2fce1f0183aa6d8836d9056789
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Sep 22, 2026.
Transparency logRelease files / repairjson-0.2.0-cp38-abi3-musllinux_1_2_i686.whl
| Download URL | repairjson-0.2.0-cp38-abi3-musllinux_1_2_i686.whl |
|---|---|
| Size | 482.5 kB |
| Tags | CPython 3.8 Linux musl 1.2+ x86-32 abi3 |
|
SHA-256 checksum How to use checksums |
b9e79ccc77622e23440a244e359e4acab38e0c575d7ef9009763da9e3ab8c89e
|
|
BLAKE2b-256 checksum How to use checksums |
82925ab94aa9d387e204740eed8e15203944216170acc21543f1fe558e00f8ec
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Sep 22, 2026.
Transparency logRelease files / repairjson-0.2.0-cp38-abi3-musllinux_1_2_armv7l.whl
| Download URL | repairjson-0.2.0-cp38-abi3-musllinux_1_2_armv7l.whl |
|---|---|
| Size | 525.1 kB |
| Tags | CPython 3.8 Linux musl 1.2+ ARMv7l abi3 |
|
SHA-256 checksum How to use checksums |
dff97c8d0d8bfc2b6d4d0a9561cf56d2130410fa487d7251703f41d8051d271d
|
|
BLAKE2b-256 checksum How to use checksums |
250d33e255f9c11248b91645204b0c54a9051ee9f30d2fa740f932ac0d0bb075
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Sep 22, 2026.
Transparency logRelease files / repairjson-0.2.0-cp38-abi3-musllinux_1_2_aarch64.whl
| Download URL | repairjson-0.2.0-cp38-abi3-musllinux_1_2_aarch64.whl |
|---|---|
| Size | 422.6 kB |
| Tags | CPython 3.8 Linux musl 1.2+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
2901489b70be32cdfde45f2e83d33c23cdd112c0cd07fef321740f5d2cdcf44f
|
|
BLAKE2b-256 checksum How to use checksums |
b243136d9eb88639dfb18dbf7be43a4c3034246024f3bc5392c32fcdbe67083f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Sep 22, 2026.
Transparency logRelease files / repairjson-0.2.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | repairjson-0.2.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 250.5 kB |
| Tags | CPython 3.8 Linux glibc 2.17+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
15a753d5407419da41f64cf84c2b16ad67f54f19b9b2c7e5bcb66b2df8c37ce8
|
|
BLAKE2b-256 checksum How to use checksums |
658a6c2ca8165402ff5c741d4a1d14b2bbd888f47464da5681bd7bedd9088251
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Sep 22, 2026.
Transparency logRelease files / repairjson-0.2.0-cp38-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl
| Download URL | repairjson-0.2.0-cp38-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl |
|---|---|
| Size | 266.5 kB |
| Tags | CPython 3.8 Linux glibc 2.17+ IBM System/390x abi3 |
|
SHA-256 checksum How to use checksums |
e9a5449ac6a872c425d16de0e7bcbfda4a8fa5257ddfbf6db114642dce4f3273
|
|
BLAKE2b-256 checksum How to use checksums |
6d0d7df4fcfa53b9eeff95bfc9011ec9ed189d7bb35b5ee5a4d899eb2f57c0f5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Sep 22, 2026.
Transparency logRelease files / repairjson-0.2.0-cp38-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
| Download URL | repairjson-0.2.0-cp38-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl |
|---|---|
| Size | 363.5 kB |
| Tags | CPython 3.8 Linux glibc 2.17+ PowerPC 64-le abi3 |
|
SHA-256 checksum How to use checksums |
ebd7c5ead3c1aaff0790d9bdf64eb3253b81fb6a894c673344e262edd374554d
|
|
BLAKE2b-256 checksum How to use checksums |
2a663a7645e3028a957c6a4a8f3e622e5c20a889ea8a9316bba7ec2f859d31a9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Sep 22, 2026.
Transparency logRelease files / repairjson-0.2.0-cp38-abi3-manylinux_2_17_i686.manylinux2014_i686.whl
| Download URL | repairjson-0.2.0-cp38-abi3-manylinux_2_17_i686.manylinux2014_i686.whl |
|---|---|
| Size | 261.7 kB |
| Tags | CPython 3.8 Linux glibc 2.17+ x86-32 abi3 |
|
SHA-256 checksum How to use checksums |
4b76f892d8b28fd2337ef580e80a6e7589514d396e57965762bf5c9e17821308
|
|
BLAKE2b-256 checksum How to use checksums |
abbcc96308fd706d2cb00f73d75c29ce2b5e1c3e00ccd816ab34638266bd4534
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Sep 22, 2026.
Transparency logRelease files / repairjson-0.2.0-cp38-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
| Download URL | repairjson-0.2.0-cp38-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl |
|---|---|
| Size | 248.3 kB |
| Tags | CPython 3.8 Linux glibc 2.17+ ARMv7l abi3 |
|
SHA-256 checksum How to use checksums |
072113abbad42febd75607d0157932e9ef3f9ef7c23e47d7b622de2055ec4033
|
|
BLAKE2b-256 checksum How to use checksums |
dcfa27e4c5eb01ec687178b84ebd2fec4577bf30d05f31ec3b462582ecd4306a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Sep 22, 2026.
Transparency logRelease files / repairjson-0.2.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
| Download URL | repairjson-0.2.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl |
|---|---|
| Size | 244.8 kB |
| Tags | CPython 3.8 Linux glibc 2.17+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
2cba1b842869b62674881e9484229fa22ddc3604b6fb5d8d84ba99ec48a62698
|
|
BLAKE2b-256 checksum How to use checksums |
31bac0a6370fd86628db06170da375aeed886d4181a19459836214db799b3e8d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Sep 22, 2026.
Transparency logRelease files / repairjson-0.2.0-cp38-abi3-macosx_11_0_arm64.whl
| Download URL | repairjson-0.2.0-cp38-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 215.8 kB |
| Tags | CPython 3.8 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
40434745f2c3f098bd99f0c80905f6d8bb4136bcf032655e8aa64e36717966aa
|
|
BLAKE2b-256 checksum How to use checksums |
ca5d51a80810f914bdb9115a0483588c3581b6e6f233a9f7fbdd91ee9958c092
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Sep 22, 2026.
Transparency logRelease files / repairjson-0.2.0-cp38-abi3-macosx_10_12_x86_64.whl
| Download URL | repairjson-0.2.0-cp38-abi3-macosx_10_12_x86_64.whl |
|---|---|
| Size | 215.9 kB |
| Tags | CPython 3.8 abi3 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
deacac748cc9ea66752d8143b77ee9998f8ad755abc774fca320da502a17b4f7
|
|
BLAKE2b-256 checksum How to use checksums |
1044134feb878f83a8ae93325fbff78006ff50a9b51ea26f5091c81617a817cb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Sep 22, 2026.
Transparency log