mrkeyoor.com_
Thu 17 Sept 23:19 UTC
AI Toolsevaluationupdated 26 Aug 2026

json_repair review

json_repair is a Python parser that turns common malformed JSON into valid data, especially output from language models, logs, APIs, and user input. It can replace `json.loads()`, repair partial streams, or use a JSON Schema or Pydantic model to guide the result.

+6stars / 7d
Verdict

Our json_repair run installed 34 packages, used 36 MB, and returned zero audit findings, while 222 tests passed and 6 schema tests failed because jsonschema was unavailable. Use it as a guarded fallback for malformed model or API output, especially when the core parser is enough. Keep strict validation after repair, install the schema extra explicitly when needed, and never treat a repaired value as proof of the sender's intent.

We ran it

Lab card: what happened when we ran json_repairScreenshot of json_repair (mangiucugna.github.io/json_repair)
Install✓ · 24s34 packages · 36 MB
Build✓ · 10s
Tests✗ · 9s222 passed · 6 failed · 92 skipped of 228 (pytest)
Known vulns0(pip-audit)
Repo87 files~9,989 lines of source · 3.2 MB · 6 CI workflows · tests dir

Answers from our run

Does json_repair build from source?

Dependencies installed in 24 seconds (34 packages), and the build succeeded in 10 seconds. We cloned commit c1a431f into a clean Debian container with 3 CPUs and no project-specific setup.

Do json_repair's tests pass?

Not all of them: 222 of 228 passed and 6 failed when we ran the project's own test command (pytest). Some failures need services or credentials a bare container does not have.

Does json_repair have known vulnerabilities in its dependencies?

pip-audit found none in the dependency tree at the time of our run.

Who should not use json_repair?

Security decisions that must reject ambiguous input: default mode invents missing delimiters and values, so strict parsing is safer there.

What are the alternatives to json_repair?

jsonrepair, JSON5, Pydantic. Our json_repair run installed 34 packages, used 36 MB, and returned zero audit findings, while 222 tests passed and 6 schema tests failed because jsonschema was unavailable.

Setup4/5Small core install; schema tests need an optional dependency
Docs5/5Clear modes, warnings, examples, CLI help, and performance guidance
Community4/5Same-day release and push, with no open issues or pull requests
Maturity4/5Core behavior is exercised; schema repair remains explicitly beta

Who it’s for

Python developers receiving almost-valid JSON from language models or unreliable integrations.
API teams that want a repair fallback before rejecting recoverable payloads.
Command-line users cleaning files or piped JSON with an inspectable local tool.
Applications that can validate repaired output against business rules before using it.

Who it’s NOT for

Security decisions that must reject ambiguous input: default mode invents missing delimiters and values, so strict parsing is safer there.
Users expecting schema repair to be settled: the README labels it beta, and our six failures all said jsonschema was required.
Workflows that pass valid JSON through skip_json_loads=True: the README warns that the repair parser may change structure or values.
Teams needing a JavaScript library: this package is Python, while the README points JavaScript users to josdejong/jsonrepair.
Systems where a syntactically valid result is automatically trusted as fact: repair can restore shape, but it cannot know whether an inferred value matches the sender's intent.

Setup reality

Our sandbox installed 34 packages in 24 seconds and used 36 MB. The build passed in 10 seconds. Tests exited 1 after 9 seconds: pytest reported 222 passed, 6 failed, and 92 skipped out of 228. Every listed failure raised ValueError: jsonschema is required when using schema-aware repair. pip-audit found 0 known vulnerabilities.

The core package needs Python 3.10 or newer and installs with pip. Basic repair has no service, database, account, or API key. Schema-guided use needs the optional json-repair[schema] dependencies, and a Pydantic model requires Pydantic v2.

The default call first tries the standard library parser, then repairs only invalid input. Keep that path for mixed valid and invalid data. CLI inline replacement can overwrite a file, so test without -i first. Schema mode is beta and cannot be combined with strict mode.

It repairs syntax, not meaning

json_repair handles the mistakes that appear when JSON is typed, streamed, logged, or generated by a model: missing quotes, commas, brackets, values, and stray prose. Its loads() function can stand in for json.loads(). Valid input goes through Python's standard parser first, while invalid input falls back to the repair parser. That design gives ordinary JSON the familiar behavior and reserves heuristics for strings that would otherwise be rejected.

The distinction between syntax and meaning should drive every adoption decision. If a payload says quantity: with no value, a repair tool may produce valid JSON, but it cannot know whether the intended value was zero, null, or omitted. The output belongs in a validation step, not directly in a payment, permission, or deletion path. json_repair is best at salvaging transport shape so an application can inspect the result and make its own decision.

The default path protects valid JSON from repair guesses

The README calls out a common wasteful pattern: try json.loads(), catch its exception, then call json_repair. The library already performs that strict first attempt. A single json_repair.loads() call returns valid JSON through the standard library and invokes repair only after parsing fails. return_objects=True avoids serializing the repaired Python object back into a JSON string when the caller needs data rather than text.

skip_json_loads=True changes that contract. It sends input straight to the repair parser and can help when the caller knows every value is malformed. The documentation warns that valid JSON can then be changed in structure or value. That makes the option unsuitable as a blanket speed switch. Mixed traffic should keep the default. A pipeline that marks known-bad model fragments separately can use the shortcut only on that branch.

Non-Latin output has another explicit switch. Passing ensure_ascii=False preserves Chinese, Japanese, Korean, and other characters instead of emitting Unicode escape sequences. File helpers mirror json.load(), while I/O errors remain the caller's job. These are sensible boundaries: the package repairs JSON structure and leaves file availability, encoding policy, and downstream validation to the application.

What happened when we ran it

Our sandbox installed 34 packages in 24 seconds and consumed 36 MB. The build completed in 10 seconds. At commit c1a431f, the repository had 87 files, roughly 9,989 lines of source, and a 3.2 MB checkout. pip-audit found zero known vulnerabilities. This was the smallest dependency and disk footprint among the Python projects in this review batch.

Tests exited 1 after 9 seconds. pytest reported 222 passed, 6 failed, and 92 skipped out of 228. All six named failures came from schema parsing or repair tests and ended with the same message: ValueError: jsonschema is required when using schema-aware repair. The log does not show a core parser failure. It also does not prove why the optional dependency was absent, so the narrow finding is that the checked-out development setup did not run every schema test successfully in our fresh container.

The result supports a split judgment. Core repair has a substantial passing suite and a clean audit in our environment. Schema use deserves a separate install and test gate. Before shipping that mode, install json-repair[schema], rerun the relevant tests, and try representative schemas from the application. Do not use the 222 passing tests to erase the six failures, and do not use the six optional-path failures to dismiss the core parser.

Strict mode is for rejection, while schema mode is for recovery

Default mode tries hard to return something useful. Strict mode instead raises ValueError on duplicate keys, missing separators, empty keys or values, multiple top-level elements, and other ambiguous structures. It is a better fit when the caller wants clearer errors but must not accept guessed structure. Strict mode can still skip the initial standard parser, though most applications should keep the ordinary validation path.

Schema-guided repair takes the opposite approach. Given JSON Schema or a Pydantic v2 model, it can fill allowed defaults, coerce selected scalars, and drop disallowed properties. Its salvage mode can discard invalid array items or map a clear array shape into an object. The README labels this feature beta, says bugs are expected, and makes it mutually exclusive with strict mode. Those rules should be visible in application configuration rather than buried in a helper function.

Streaming support uses stream_stable=True to keep partial output repairable as more text arrives. This can help a UI display evolving model output, but partial validity should remain provisional. A closing chunk may change the structure or reveal that an earlier guessed value was wrong. Persist only the final validated object unless the product explicitly models partial state.

The project is current and unusually candid about unsafe shortcuts

Version 0.63.4 was released on August 25, 2026, the same date as the latest repository push. GitHub showed no open issues or pull requests. The README documents the dangerous cases directly: valid input can change when forced through repair, schema behavior is beta, strict and schema modes conflict, and inline CLI use overwrites files. That candor is more useful than a promise that every malformed string can be recovered.

Choose json_repair when invalid JSON is common enough to justify a shared, tested fallback. JSON5 is better for a known permissive syntax, Pydantic is better once data already parses, and the JavaScript jsonrepair project fits Node.js. In Python, this package earns a place between raw input and validation. It should not sit between validation and a consequential side effect.

Alternatives

ProjectWhat it isPick it when
jsonrepairA JavaScript repair library and streaming transform for malformed JSON text.pick this instead when the application runs on Node.js or needs the JavaScript streaming API.
JSON5A parser for a defined JSON superset with comments, trailing commas, and friendlier syntax.pick this instead when inputs intentionally follow JSON5 and should be parsed by a specification rather than repaired heuristically.
Pydantic gh↗Typed Python validation and coercion for data that already has a parseable structure.pick this instead when schema validation, typed errors, and controlled coercion matter more than recovering broken JSON syntax.

Sources

  1. json_repair README
  2. json_repair 0.63.4 release
  3. json_repair documentation

More ai tools reviews

rowboat · skills · superpowers-zh · yolov5 · eve · MemOS · the whole board →