Metadata-Version: 2.4
Name: laga
Version: 0.1.1
Summary: Repair malformed JSON from language models and hand-written config.
Project-URL: Homepage, https://github.com/olaflaitinen/laga
Project-URL: Documentation, https://github.com/olaflaitinen/laga/tree/main/docs
Project-URL: Source, https://github.com/olaflaitinen/laga
Project-URL: Issue Tracker, https://github.com/olaflaitinen/laga/issues
Author: Gustav Olaf Yunus Laitinen-Fredriksson Lundström-Imanov
License: MIT License
        
        Copyright (c) 2026 Gustav Olaf Yunus Laitinen-Fredriksson Lundström-Imanov
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Keywords: data-cleanup,json,llm,parser,repair
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Typing :: Typed
Requires-Python: <3.14,>=3.10
Provides-Extra: dev
Requires-Dist: build>=1.2; extra == 'dev'
Requires-Dist: coverage[toml]>=7.6; extra == 'dev'
Requires-Dist: hypothesis>=6.108; extra == 'dev'
Requires-Dist: mkdocs-material>=9.5; extra == 'dev'
Requires-Dist: mkdocs>=1.6; extra == 'dev'
Requires-Dist: mypy>=1.11; extra == 'dev'
Requires-Dist: pre-commit>=3.8; extra == 'dev'
Requires-Dist: pytest-cov>=5.0; extra == 'dev'
Requires-Dist: pytest>=8.3; extra == 'dev'
Requires-Dist: ruff>=0.6.9; extra == 'dev'
Provides-Extra: docs
Requires-Dist: mkdocs-material>=9.5; extra == 'docs'
Requires-Dist: mkdocs>=1.6; extra == 'docs'
Provides-Extra: lint
Requires-Dist: mypy>=1.11; extra == 'lint'
Requires-Dist: ruff>=0.6.9; extra == 'lint'
Provides-Extra: test
Requires-Dist: coverage[toml]>=7.6; extra == 'test'
Requires-Dist: hypothesis>=6.108; extra == 'test'
Requires-Dist: pytest-cov>=5.0; extra == 'test'
Requires-Dist: pytest>=8.3; extra == 'test'
Description-Content-Type: text/markdown

# 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.

```bash
python -m pip install -e ".[dev]"
```

## Quickstart

```python
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
```
