SalvaJSON: repair and parse malformed JSON
SalvaJSON fixes broken JSON that standard parsers reject, then parses it into Python objects. It's a drop-in upgrade for json.loads() when your input comes from LLMs, scraped pages, hand-edited configs, or any source that doesn't guarantee strict JSON.
What it fixes
SalvaJSON uses jsonic — a lenient JavaScript JSON parser — to handle:
- Unquoted keys —
{name: "Alice"}instead of{"name": "Alice"} - Single quotes —
{'key': 'value'}instead of{"key": "value"} - Trailing commas —
[1, 2, 3,]and{"a": 1,} - Missing commas —
[1 2 3]parsed as[1, 2, 3] - JavaScript comments —
// line commentsand/* block comments */ - Unquoted string values —
{status: active}whereactiveis unambiguous
Valid JSON is parsed at full speed by orjson without touching the repair path.
Install
pip install salvajson
Requires Python 3.10+. Pulls in pythonmonkey (embeds SpiderMonkey JS engine) and orjson.
Usage
Python API
from salvajson import salvaj, loads, dumps
# Repair a broken JSON string → returns valid JSON string
salvaj('{name: "Alice", age: 30,}')
# → '{"name":"Alice","age":30}'
# Parse JSON → Python object (auto-repairs on failure)
loads('{"id": 1}') # fast path via orjson
loads("{id: 1, tags: ['a', 'b'],}") # repair path via jsonic
# → {'id': 1, 'tags': ['a', 'b']}
# Serialize Python → JSON string (via orjson, fast)
dumps({"name": "Alice", "scores": [1, 2]})
dumps({"b": 2, "a": 1}, sort_keys=True, indent=2)
loads() and dumps() accept the same keyword arguments as json.loads() / json.dumps() for compatibility, though most are no-ops (orjson handles them natively).
CLI
# Repair a file and print to stdout
python -m salvajson broken.json
# Repair and save
python -m salvajson broken.json > fixed.json
# Pipe
echo '{key: "value"}' | python -m salvajson
How it works
loads(s)
├── orjson.loads(s) → fast path if valid JSON
└── on JSONDecodeError:
salvaj(s) → jsonic via PythonMonkey SpiderMonkey engine
└── JSON.stringify() → valid JSON string
orjson.loads(repaired) → Python object
The JavaScript engine is embedded in-process via PythonMonkey — no Node.js required, no subprocess overhead.
API reference
| Function | Signature | Description |
|---|---|---|
salvaj |
(json_str: str) -> str |
Repair broken JSON; return valid JSON string |
loads |
(s: bytes | str, **kw) -> Any |
Parse JSON with automatic repair fallback |
dumps |
(obj, *, indent=None, sort_keys=False, **kw) -> str |
Serialize to JSON string |
Performance notes
- Valid JSON:
orjsonis used directly — among the fastest Python JSON parsers. - Invalid JSON: repair path invokes SpiderMonkey JS engine via PythonMonkey; adds latency (~ms).
- The JS bundle is loaded once at import time.
Development
git clone https://github.com/twardoch/salvajson && cd salvajson
./dev.sh setup # creates venv, installs Python + JS deps, pre-commit hooks
./dev.sh test # pytest
./dev.sh lint # ruff + mypy + bandit + prettier
./dev.sh build # hatch build
The JS source lives in js_src/salvajson.src.js and is bundled into src/salvajson/salvajson.js by esbuild during build.
License
Apache License 2.0. See LICENSE.
Metadata
Release files for salvajson 1.7.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| salvajson-1.7.2.tar.gz | 35.5 kB | With provenance | Details for salvajson-1.7.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| salvajson-1.7.2-py3-none-any.whl | Python 3 | none | any | Details for salvajson-1.7.2-py3-none-any.whl |
Total release size: 63.3 kB
Release files / salvajson-1.7.2.tar.gz
| Download URL | salvajson-1.7.2.tar.gz |
|---|---|
| Size | 35.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b17483752889d5d32318c7ba32d4ee438ce5a148eb01cbba9f4235233e227e38
|
|
BLAKE2b-256 checksum How to use checksums |
dcf8f5083358f325c891f3d80e4fd9095653bd15693eb9bfd560f8edc3b9ade4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Nov 17, 2026.
Transparency logRelease files / salvajson-1.7.2-py3-none-any.whl
| Download URL | salvajson-1.7.2-py3-none-any.whl |
|---|---|
| Size | 27.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
dc01a63d18d5a01fb00e001e03225623c7c4516f7d20561fe66aef23ce43ebf5
|
|
BLAKE2b-256 checksum How to use checksums |
e02f79bec6260309f5ce4e1fec2fb9ba8a79b3699bbd4a9624c7e80a611b431a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Nov 17, 2026.
Transparency logSecurity for salvajson 1.7.2
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.
Attestation for salvajson-1.7.2.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 Nov 17, 2026.
Transparency logA 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.