Metadata-Version: 2.4
Name: laga
Version: 0.1.2
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.

It is built for the real world: model output, hand-written config, copied snippets, and other almost-JSON text that is usually close enough to recover but not strict enough for `json.loads`.

## Highlights

- Repairs common JSON mistakes such as trailing commas, missing commas, single quotes, unquoted keys, comments, fences, smart quotes, and truncated containers.
- Tries the standard library first, so valid JSON stays fast and strict.
- Keeps the public API small: `repair`, `repair_to_str`, `loads`, and `LagaError`.
- Ships with a CLI, type information, tests, docs, and CI.

## Supported Versions

`laga` 0.1.2 supports Python 3.10 through 3.13.

## Install

For normal use from PyPI:

```bash
python -m pip install laga
```

For local development from a checkout:

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

## Quick Start

```python
import laga

text = "{name: 'Ada', active: True, roles: ['admin', 'writer',],}"

data = laga.repair(text)
print(data)
print(laga.repair_to_str(text))
```

## CLI

You can also use `laga` from the command line:

```bash
laga "{name: 'Ada', active: True, roles: ['admin',]}"
laga --strict '{"a": 1,}'
```

Use `--strict` when you want to reject ambiguous repairs instead of filling in gaps.
Use `--pretty` to format output for humans, `--stdin` to read from standard input, and `--duplicate-keys error` when duplicate keys should fail.

```bash
laga --stdin --pretty
laga --max-depth 64 --max-input-size 10000 --duplicate-keys error '{"a": 1}'
```

## API

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

## What It Repairs

| 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]}` |

## Strict Mode

`strict=True` is for validation workflows where you want `laga` to fail instead of guessing.

In strict mode, `laga` rejects ambiguous recoveries such as:

- missing commas between object members or array items
- unterminated objects or arrays
- other repairs that would require filling in structure the input did not clearly provide

## Behavior Notes

- `json.loads` is still the best choice when you control the producer and the input is already valid JSON.
- Duplicate keys use last-value-wins behavior, matching Python dict semantics.
- Use `duplicate_keys="error"` when you want duplicate object members to fail instead of being merged.
- `laga` does not evaluate expressions or try to invent arbitrary JavaScript syntax.
- The parser is intentionally conservative around malformed numbers and highly ambiguous text.

## When To Use `laga`

Use `laga` when the input is noisy, user-facing, or generated by a model and you need a predictable repair step before parsing.

Use `json.loads` when correctness and strictness matter more than recovery.

## Development

```bash
make install
make lint
make typecheck
make test
make build
```

## Project Links

- Documentation: [docs/index.md](docs/index.md)
- API details: [docs/api.md](docs/api.md)
- Usage examples: [docs/usage.md](docs/usage.md)
- Contributing guide: [CONTRIBUTING.md](CONTRIBUTING.md)

## Citation

If you use `laga` in academic work, research notes, or other formal writing, please cite the repository using the metadata in [CITATION.cff](CITATION.cff).

Suggested citation format:

```text
	Laitinen-Fredriksson Lundström-Imanov, G. O. Y. (2026). laga (Version 0.1.2) [Computer software]. https://github.com/olaflaitinen/laga
```