AtlatestRepositorysigil-json
sigil-json / treeREADME.md
1
# sigil-json3
JSON parsing and generation for [Sigil](https://codeberg.org/sigil/sigil).5
Bidirectional conversion between JSON and native Scheme types (dicts,6
arrays, strings, numbers, booleans) with port-based I/O for reading and7
writing JSON streams.9
This package was extracted from the sigil monorepo — the in-tree history10
under `packages/sigil-json/` is preserved here as `master`.12
## Usage14
```scheme15
(import (sigil json))17
;; Encode18
(json-encode #{ name: "Alice" age: 30 })19
; => "{\"name\":\"Alice\",\"age\":30}"21
;; Decode22
(json-decode "{\"name\":\"Alice\",\"age\":30}")23
; => #{ name: "Alice" age: 30 }25
;; Path lookup26
(json-get-in (json-decode "{\"a\":{\"b\":42}}") '(a b))27
; => 4228
```30
## Type Mapping32
| JSON | Scheme |33
|--------|----------------------------|34
| object | dict: `#{ name: "Alice" }` |35
| array | array: `#[1 2 3]` |36
| string | string: `"hello"` |37
| number | number: `42`, `3.14` |38
| true | `#t` |39
| false | `#f` |40
| null | `'null` symbol |42
JSON `null` decodes as the symbol `'null` (not `#f`). When a field may be43
JSON null, normalize it explicitly — see `docs/json.md` for the pattern.45
## API47
### `(sigil json)`49
| Procedure | Purpose |50
|-----------|---------|51
| `json-encode` | Scheme value → JSON string |52
| `json-decode` | JSON string → Scheme value |53
| `json-read` / `json-write` | Port-based streaming I/O |54
| `json-get-in` | Path lookup into a decoded value |56
See `docs/json.md` for full details.58
## Dependencies60
- `sigil-stdlib`62
Consumed here as a `from-git` ref pinned to `^0.13.1` against the sigil63
monorepo.65
## Build67
```sh68
sigil deps install69
sigil build70
```72
## Testing74
```sh75
sigil test76
```78
## License80
BSD-3-Clause.