Repair malformed JSON from language models and hand-written config.
Project description
laga
laga repairs malformed JSON and returns Python objects.
Why
Large language models and hand-written configuration often produce almost-JSON with trailing commas, missing commas, comments, code fences, single quotes, unquoted keys, or truncated containers. laga keeps the public surface small, tries json.loads first for valid input, and only enters the repair path when necessary.
Install
laga 0.1.1 supports Python 3.10 through 3.13.
python -m pip install -e ".[dev]"
Quickstart
import laga
text = """Here is the result:
```json
{
'name': 'Ada',
'active': True,
'roles': ['admin', 'writer',],
}
"""
data = laga.repair(text) print(data) print(laga.repair_to_str(text))
## API Reference
| Function | Returns | Description |
| --- | --- | --- |
| `laga.repair(text, strict=False)` | Python object | Repairs malformed JSON and returns Python data. |
| `laga.repair_to_str(text, strict=False)` | `str` | Repairs malformed JSON and returns normalized JSON text. |
| `laga.loads(text, strict=False)` | Python object | Alias for `laga.repair`. |
| `laga.LagaError` | Exception type | Raised when repair fails or input is unrecoverable. |
## Repair Rules
| Rule | Before | After |
| --- | --- | --- |
| Trailing comma | `{"a": 1,}` | `{"a":1}` |
| Missing comma | `{"a": 1 "b": 2}` | `{"a":1,"b":2}` |
| Single quotes | `{'a': 'b'}` | `{"a":"b"}` |
| Unquoted keys | `{name: "Ada"}` | `{"name":"Ada"}` |
| Python literals | `{"ok": True, "none": None}` | `{"ok":true,"none":null}` |
| Comments | `{"a": 1 // note\n}` | `{"a":1}` |
| Markdown fences | <code>```json\n{"a":1}\n```</code> | `{"a":1}` |
| Smart quotes | `“a”` | `"a"` |
| Prose around JSON | `Result: {"a":1}` | `{"a":1}` |
| Truncated structure | `{"a": [1, 2` | `{"a":[1,2]}` |
## Limitations
`laga` is intentionally conservative. It does not evaluate expressions, it does not guess at arbitrary JavaScript syntax, and it does not try to recover malformed numbers or deeply ambiguous text in strict mode. If you already control the producer and the input is valid JSON, the standard library remains the best choice because `json.loads` is faster and stricter.
When an object contains duplicate keys, the last value wins, matching Python dict behavior.
## When To Use The Standard Library
Use `json.loads` when you control the producer and know the input is valid JSON. Use `laga` when the input is noisy, user-facing, or generated by a model and you need a predictable repair step before parsing.
## Development
```bash
make install
make lint
make typecheck
make test
make build
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file laga-0.1.1.tar.gz.
File metadata
- Download URL: laga-0.1.1.tar.gz
- Upload date:
- Size: 17.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a57a97825490c0e58445413de303c0ad99850cdc2c5dfb355feb779c9a34aa47
|
|
| MD5 |
9972a457e90f897c5fdd9ef2aec84529
|
|
| BLAKE2b-256 |
a16121050eece50b0321b860dc0c6d7c6766eb64ff0a15c53e23831676946627
|
Provenance
The following attestation bundles were made for laga-0.1.1.tar.gz:
Publisher:
release.yml on olaflaitinen/laga
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
laga-0.1.1.tar.gz -
Subject digest:
a57a97825490c0e58445413de303c0ad99850cdc2c5dfb355feb779c9a34aa47 - Sigstore transparency entry: 2232393159
- Sigstore integration time:
-
Permalink:
olaflaitinen/laga@cad74b6e83d4819235839c5c451f1331adf67216 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/olaflaitinen
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@cad74b6e83d4819235839c5c451f1331adf67216 -
Trigger Event:
push
-
Statement type:
File details
Details for the file laga-0.1.1-py3-none-any.whl.
File metadata
- Download URL: laga-0.1.1-py3-none-any.whl
- Upload date:
- Size: 9.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
48a5eef6f5702ac7e03e970d487dab875cf730091b97b66cc548d25e6be0faee
|
|
| MD5 |
cc4d3c9c7842fc3b348a082f46f8d7b2
|
|
| BLAKE2b-256 |
f8a6f5649faf2338af17bd13701f4575dbc4dd1baffc0d3716341c79c199362d
|
Provenance
The following attestation bundles were made for laga-0.1.1-py3-none-any.whl:
Publisher:
release.yml on olaflaitinen/laga
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
laga-0.1.1-py3-none-any.whl -
Subject digest:
48a5eef6f5702ac7e03e970d487dab875cf730091b97b66cc548d25e6be0faee - Sigstore transparency entry: 2232393767
- Sigstore integration time:
-
Permalink:
olaflaitinen/laga@cad74b6e83d4819235839c5c451f1331adf67216 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/olaflaitinen
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@cad74b6e83d4819235839c5c451f1331adf67216 -
Trigger Event:
push
-
Statement type: