Skip to main content

repairjson

CI PyPI Python License: MIT

repairjson is a Rust-backed Python library that turns common forms of malformed, LLM-style JSON into valid JSON. It is useful at system boundaries where model output is close to JSON but may contain Python literals, missing punctuation, Markdown fences, or a truncated container.

What it repairs

  • Single-quoted strings and unquoted object keys
  • Python literals such as True, False, and None
  • Missing or trailing commas
  • Truncated objects and arrays
  • Common malformed number forms
  • Raw newlines, tabs, and control characters inside strings
  • Leading Markdown fences and conversational preambles before an object or array

The repair engine is byte-oriented and returns compact JSON. loads() performs repair and then delegates deserialization to Python's standard json module.

Installation

python -m pip install repairjson

Quick start

import repairjson

source = "{user: 'alice', active: True, tags: ['x', 'y',],}"

fixed = repairjson.repair(source)
print(fixed)
# {"user":"alice","active":true,"tags":["x","y"]}

value = repairjson.loads(source)
print(value["user"])
# alice

API

repairjson.repair(input: str) -> str

Returns a repaired JSON string. For example:

repairjson.repair("Here is the JSON:\n```json\n{answer: 42}\n```")
# '{"answer":42}'

repairjson.loads(input: str) -> object

Repairs the input and returns the Python value produced by json.loads().

repair_to_string() and repair_json() remain available as compatibility aliases for repair().

Limitations and safety

Repair is heuristic and can be lossy. Ambiguous input may have more than one reasonable interpretation; callers should validate the returned value against an expected schema before using it. The library extracts the first object or array found after a conversational preamble and ignores trailing prose after the parsed value.

This package does not perform schema validation, stream parsing, or security policy enforcement. Apply normal input-size and nesting limits when processing untrusted data. If exact preservation is required, reject malformed input instead of repairing it.

The package is currently an alpha release. See CHANGELOG.md for release history.

Benchmarking

The benchmark harness compares repairjson with the Python json-repair package across generated malformed-input profiles:

uv run --extra benchmark python benchmark.py --dataset all

The benchmark requires Python 3.10 or newer because of its comparison dependency. It checks a sample for semantic equivalence before reporting timings. Results vary with hardware, package versions, and input shape, so the project does not claim a fixed speedup.

Development

Prerequisites: Python 3.8 or newer, Rust stable, and uv.

git clone https://github.com/kyle-mirich/repairjson.git
cd repairjson
uv venv
uv pip install -e ".[dev]"

Run the same checks used by CI:

cargo fmt --check
cargo clippy --all-targets -- -D warnings
cargo test
.venv/bin/python -m pytest -q

Build and inspect release artifacts:

.venv/bin/maturin build --release --sdist -i .venv/bin/python -o dist
.venv/bin/twine check dist/*

Project structure

  • src/lexer.rs: byte-level input traversal and fence handling
  • src/parser.rs: repair state machine and normalization logic
  • src/lib.rs: PyO3 Python API
  • python/tests/: end-to-end Python API tests
  • benchmark.py: generated-corpus benchmark harness
  • .github/workflows/CI.yml: checks, wheels, attestations, and trusted publishing
  • docs/flows.md: repair and release flows

Contributing

See CONTRIBUTING.md for setup and pull request expectations.

Report security issues privately as described in SECURITY.md.

License

MIT. See LICENSE.

Metadata

Release files for repairjson 0.1.3

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

Source distribution (sdist)

Source distribution for repairjson 0.1.3
File Size Uploaded
repairjson-0.1.3.tar.gz 15.8 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for repairjson 0.1.3
File
repairjson-0.1.3-cp38-abi3-win_arm64.whl CPython 3.8 abi3 Windows ARM64 Details
repairjson-0.1.3-cp38-abi3-win_amd64.whl CPython 3.8 abi3 Windows x86-64 Details
repairjson-0.1.3-cp38-abi3-win32.whl CPython 3.8 abi3 Windows x86-32 Details
repairjson-0.1.3-cp38-abi3-musllinux_1_2_x86_64.whl CPython 3.8 abi3 Linux musl 1.2+ x86-64 Details
repairjson-0.1.3-cp38-abi3-musllinux_1_2_i686.whl CPython 3.8 abi3 Linux musl 1.2+ x86-32 Details
repairjson-0.1.3-cp38-abi3-musllinux_1_2_armv7l.whl CPython 3.8 abi3 Linux musl 1.2+ ARMv7l Details
repairjson-0.1.3-cp38-abi3-musllinux_1_2_aarch64.whl CPython 3.8 abi3 Linux musl 1.2+ ARM64 Details
repairjson-0.1.3-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.8 abi3 Linux glibc 2.17+ x86-64 Details
repairjson-0.1.3-cp38-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl CPython 3.8 abi3 Linux glibc 2.17+ IBM System/390x Details
repairjson-0.1.3-cp38-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl CPython 3.8 abi3 Linux glibc 2.17+ PowerPC 64-le Details
repairjson-0.1.3-cp38-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl CPython 3.8 abi3 Linux glibc 2.17+ ARMv7l Details
repairjson-0.1.3-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.8 abi3 Linux glibc 2.17+ ARM64 Details
repairjson-0.1.3-cp38-abi3-manylinux_2_5_i686.manylinux1_i686.whl CPython 3.8 abi3 Linux glibc 2.5+ x86-32 Details
repairjson-0.1.3-cp38-abi3-macosx_11_0_arm64.whl CPython 3.8 abi3 macOS 11.0+ ARM64 Details
repairjson-0.1.3-cp38-abi3-macosx_10_12_x86_64.whl CPython 3.8 abi3 macOS 10.12+ x86-64 Details

Total release size: 4.2 MB

Release files / repairjson-0.1.3.tar.gz

Download URL repairjson-0.1.3.tar.gz
Size 15.8 kB
Tags Source
SHA-256 checksum
How to use checksums
4f08494563a358c07090309545d342b1ae2ecbe241db4eb04cd2b9a66df5f6c3
BLAKE2b-256 checksum
How to use checksums
ff784467faa2c137694fe29f6cfebdde73c2a8299d54476bcf8499e79c2da2f3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.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 Jul 23, 2026.

Transparency log

Release files / repairjson-0.1.3-cp38-abi3-win_arm64.whl

Download URL repairjson-0.1.3-cp38-abi3-win_arm64.whl
Size 108.9 kB
Tags CPython 3.8 Windows ARM64 abi3
SHA-256 checksum
How to use checksums
a51c34fd339df17c53a419f274337d718305461c3a4ee50fdc0e270bfc846bd3
BLAKE2b-256 checksum
How to use checksums
95d1c7f04c740b95af923e4f9d8630d2ec1a4340c5efab3c5f749128bdbd3230
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.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 Jul 23, 2026.

Transparency log

Release files / repairjson-0.1.3-cp38-abi3-win_amd64.whl

Download URL repairjson-0.1.3-cp38-abi3-win_amd64.whl
Size 108.6 kB
Tags CPython 3.8 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
1ac19c0d3a229001d3bc120a56e2479449827f7f15b42db5483e0297184d2a57
BLAKE2b-256 checksum
How to use checksums
abc7312bb1d27817ecb352c98b649f76d24008e49313faf17394cbfa26c04ebd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.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 Jul 23, 2026.

Transparency log

Release files / repairjson-0.1.3-cp38-abi3-win32.whl

Download URL repairjson-0.1.3-cp38-abi3-win32.whl
Size 103.2 kB
Tags CPython 3.8 Windows x86-32 abi3
SHA-256 checksum
How to use checksums
efb0ee54180939a2cbfb80eb9916243e8347e18cd89d47ad7b4c851c1389b38d
BLAKE2b-256 checksum
How to use checksums
d044f584a796bb106be53a3d592ed4d886b25052af693fa24275a0520a136235
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.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 Jul 23, 2026.

Transparency log

Release files / repairjson-0.1.3-cp38-abi3-musllinux_1_2_x86_64.whl

Download URL repairjson-0.1.3-cp38-abi3-musllinux_1_2_x86_64.whl
Size 445.3 kB
Tags CPython 3.8 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
83c98103d774b113dbe087ff6c1e2a0d7da6bfd3930c7dbb4298483437308cc9
BLAKE2b-256 checksum
How to use checksums
e2f46f92ff1e1e6e5c9dbd024cad7314faf799dd278269c0d5b0b77418d43805
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.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 Jul 23, 2026.

Transparency log

Release files / repairjson-0.1.3-cp38-abi3-musllinux_1_2_i686.whl

Download URL repairjson-0.1.3-cp38-abi3-musllinux_1_2_i686.whl
Size 477.2 kB
Tags CPython 3.8 Linux musl 1.2+ x86-32 abi3
SHA-256 checksum
How to use checksums
39de7c9c3373da0b9bbd90193ffbf794732cd8e6d93793129a9c9fe3d87fde47
BLAKE2b-256 checksum
How to use checksums
a4bebfb0a77b8d196e3bdb8c8b17b1326a3a6153f805b6e381313cdc362c75b0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.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 Jul 23, 2026.

Transparency log

Release files / repairjson-0.1.3-cp38-abi3-musllinux_1_2_armv7l.whl

Download URL repairjson-0.1.3-cp38-abi3-musllinux_1_2_armv7l.whl
Size 517.8 kB
Tags CPython 3.8 Linux musl 1.2+ ARMv7l abi3
SHA-256 checksum
How to use checksums
e10a453330e9ed4e6e7cf0d48b0ca17c8e7b768e5c6b76e15226e182ab8a7212
BLAKE2b-256 checksum
How to use checksums
b2c622d79067b8bc2638366da310bbd77ec6342cd1e90d4166cbcc874080eeb2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.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 Jul 23, 2026.

Transparency log

Release files / repairjson-0.1.3-cp38-abi3-musllinux_1_2_aarch64.whl

Download URL repairjson-0.1.3-cp38-abi3-musllinux_1_2_aarch64.whl
Size 415.2 kB
Tags CPython 3.8 Linux musl 1.2+ ARM64 abi3
SHA-256 checksum
How to use checksums
e47bf5775ad050cf994683061067f97e9a6a60575c34bfcaa93b05e43c249ec8
BLAKE2b-256 checksum
How to use checksums
248f992a6ca68824ad40c7cca5275dc8d08b1f2feb53bfc636130552f4a38c38
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.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 Jul 23, 2026.

Transparency log

Release files / repairjson-0.1.3-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL repairjson-0.1.3-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 244.1 kB
Tags CPython 3.8 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
d5678fcec92ed5fb69440c790a2eee4430fb1af5837ac3d06515c7d7bdb09635
BLAKE2b-256 checksum
How to use checksums
db02f0a26e1ff7dae691065e5f5136557c96f7524a0ef9799d8d5a8276d8ec82
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.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 Jul 23, 2026.

Transparency log

Release files / repairjson-0.1.3-cp38-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl

Download URL repairjson-0.1.3-cp38-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl
Size 261.2 kB
Tags CPython 3.8 Linux glibc 2.17+ IBM System/390x abi3
SHA-256 checksum
How to use checksums
d97bbf59cde7de95609043b50746ad16db97a14a677100dcc3ff336a39cf7c86
BLAKE2b-256 checksum
How to use checksums
050628a836d7d07a525d28f231473b7df3e4cd97ce3c0f2faa7248e97c879d5d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.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 Jul 23, 2026.

Transparency log

Release files / repairjson-0.1.3-cp38-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl

Download URL repairjson-0.1.3-cp38-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Size 360.5 kB
Tags CPython 3.8 Linux glibc 2.17+ PowerPC 64-le abi3
SHA-256 checksum
How to use checksums
a4978bd22d8beadf264304a52d1d45efaa9061da0963762036a788ed27171ee6
BLAKE2b-256 checksum
How to use checksums
6fa0b8364bde29139b7880744416bdde9d3492089e09950ecf9bfc0b1f4e066f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.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 Jul 23, 2026.

Transparency log

Release files / repairjson-0.1.3-cp38-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl

Download URL repairjson-0.1.3-cp38-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Size 243.1 kB
Tags CPython 3.8 Linux glibc 2.17+ ARMv7l abi3
SHA-256 checksum
How to use checksums
863049e69a2635ba16372ebfe355ccbc356af2c24913ccd2ff1d8e09e14a1acc
BLAKE2b-256 checksum
How to use checksums
9679bf163a5586d99f7953dac988b3ce8b4ad83e1bba6b5bdc650364a165e2e8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.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 Jul 23, 2026.

Transparency log

Release files / repairjson-0.1.3-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL repairjson-0.1.3-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 239.2 kB
Tags CPython 3.8 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
cf0d10e60e02091ffd94f4330b38b27125aa101821a8230dc5d108aa03ca1cfc
BLAKE2b-256 checksum
How to use checksums
c5cc55b28f6aaf3d8236ddfe93b66f1bb03a7350d41af12c7229617b1e6756c1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.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 Jul 23, 2026.

Transparency log

Release files / repairjson-0.1.3-cp38-abi3-manylinux_2_5_i686.manylinux1_i686.whl

Download URL repairjson-0.1.3-cp38-abi3-manylinux_2_5_i686.manylinux1_i686.whl
Size 257.2 kB
Tags CPython 3.8 Linux glibc 2.5+ x86-32 abi3
SHA-256 checksum
How to use checksums
77d0d4fa727674f60bb6ad2a7bc96dbf47ee43ab3233b03794f7bfe31a9625da
BLAKE2b-256 checksum
How to use checksums
f7987ad955486852f974b0e689ccff04a0ed14eaf6e2e9963db79a558f4ce6b4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.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 Jul 23, 2026.

Transparency log

Release files / repairjson-0.1.3-cp38-abi3-macosx_11_0_arm64.whl

Download URL repairjson-0.1.3-cp38-abi3-macosx_11_0_arm64.whl
Size 213.0 kB
Tags CPython 3.8 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
4894fb239c0ef8d28c561bf17072913838511ee088aef036babb466852efad1b
BLAKE2b-256 checksum
How to use checksums
278c7b20096ba5692303366ce550d011afec04179d0355e4fd4353ad561e3745
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.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 Jul 23, 2026.

Transparency log

Release files / repairjson-0.1.3-cp38-abi3-macosx_10_12_x86_64.whl

Download URL repairjson-0.1.3-cp38-abi3-macosx_10_12_x86_64.whl
Size 213.0 kB
Tags CPython 3.8 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
fa442b5bdb97fac5d682963f6bb8076090d87256de7985aaf56929ca6c7595a1
BLAKE2b-256 checksum
How to use checksums
3c23d7899da0cecea2e04fa28a773d011dd82852d966e465dff0a96732f18811
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.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 Jul 23, 2026.

Transparency log

Release history Release notifications | RSS feed

0.2.0

16 release files

This release

0.1.3 This release

16 release files

0.1.1

18 release files

0.1.0

18 release files

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