Metadata-Version: 2.3
Name: json5rt
Version: 0.1.0
Summary: json5rt — JSON5 round-trip library: load, edit, and save JSON5 files with comment preservation
Author: Tobias Hochgürtel
Author-email: Tobias Hochgürtel <tobias.hochguertel@googlemail.com>
Requires-Dist: json-five>=1.1.0
Requires-Python: >=3.13
Description-Content-Type: text/markdown

# json5rt

JSON5 round-trip library: load, edit, and save JSON5 files with comment preservation.

## Why?

Two PyPI packages — `json5` and `json-five` — both use the import name `json5`, but their APIs are not interchangeable. Neither makes comment-preserving round-trip editing easy.

`json5rt` wraps `json-five`'s model API in a clean, dict-like interface with a non-colliding import name (`import json5rt`).

## Installation

```bash
uv add json5rt
# or
pip install json5rt
```

## Quick start

```python
import json5rt

# Load a JSON5 file with comments
doc = json5rt.load("config.json5")

# Edit like a dict
doc["port"] = 9090
doc["ssl"] = False
del doc["features"]

# Save back — comments preserved!
doc.save()

# Create from scratch
doc = json5rt.Document()
doc["host"] = "localhost"
doc["port"] = 8080
doc.save("new_config.json")  # valid JSON (double-quoted, no comments)
```

## API

### Functional

- `json5rt.load(path)` — Load from file, returns `Document`
- `json5rt.loads(text)` — Load from string, returns `Document`
- `json5rt.dump(doc, path)` — Write to file
- `json5rt.dumps(doc)` — Serialize to string

### Document (dict-like)

- `doc["key"]` — Get value
- `doc["key"] = value` — Set/add key
- `del doc["key"]` — Delete key
- `"key" in doc` — Check existence
- `doc.keys()`, `doc.values()`, `doc.items()`
- `doc.get(key, default)`
- `doc.update(dict)`
- `doc.save()` / `doc.save(path)` / `doc.save_as(path)`
- `doc.to_dict()` — Plain dict (comments lost)
- `doc.to_json()` — Strict JSON string
- `doc.dumps()` — JSON5/JSONC string (comments preserved)

## License

MIT
