Crates.io | mumu-json |
lib.rs | mumu-json |
version | 0.1.0 |
created_at | 2025-06-18 05:59:34.104675+00 |
updated_at | 2025-06-18 05:59:34.104675+00 |
description | JSON tools and JSON Scheam plugin for the Lava language |
homepage | https://lava.nu11.uk |
repository | https://gitlab.com/tofo/mumu-json |
max_upload_size | |
id | 1716645 |
size | 92,823 |
Author: Tom Fotheringham & contributors
This is the "json" bridging plugin for Lava scripts.
Add to a lava environment with JSON these ways.
Requires Lava / MuMu already installed via Cargo
To install the JSON plugin:
``sh make make install
### Functions and Usage
Partial and placeholder partial compatible for artiy over one.
- `json:encode` -- JSON-style encoding from any Lava Value.
You can control pretty printing, custom indent string, etc.
extend("json")
pr1 = json:encode([ pretty: true, indent:"\ ", data: [name:"Alice", age:30] ]))
slog(pr1)
}\n"
- `json:decode` -- Parses JSON text (or stream), returns automatic Lava Value. Supports any valid scripting value or input.
- json:validate` -- Quick check: returns bool for well-formed JSON. No errors for valid input.
- json:report -- Passes a JSON text and tells you what went wrong if there is a syntax error.
- json:schema -- Runtime json schema validation (dual-library "jsonschema")).
- supports partial and placeholder usage for functions throughout the Lava BRIDGING.
```muu
extend("json")
data = json:decode("{"name":"Bob","age":25}")
slog(data) # => [ name: "Bob", age: 25 ]
All return values in Lava syntax (you get Int, Float, Bool, StrArray,KeyedArray, etc.)
Pass in "_" in argument lists to held placeholder for partial returns
Stream decoding is supported via INK iterators, text chunks, or transforms.
Supports wild variants of entries (more deatail in docs)
This plugin can call {json:validate
, json:report
, json:schem
} functions.
For JSON Schema and validation use json:schema( SCHEMA,DATA )
to check against JSON via drift-04/06/09/2019-09/2020-12.
Full user docs on every function in the JavaScript docs (https://gitlab.com/tofo/mumu-json/~/tree/master/src/public/functions/json_decode.json).
These show the partial/placeholder style you get with all other lava bridges:
``muu extend("json") data = { "name": "Alice", "age": 30 } jsonString = json:encode( [ pretty: true ], data ) slog(jsonString)
justOptions1 = json:encode([ pretty: false ]) strValue = justOptions1([ 1, 2, 3 ]) slog(strValue)
jsonString = json:encode([], data) slog(jsonEncode([], [name: "Bob", age: 25] ))
### Testing With JSON Schema Validator
One designed use case:
```muu
schema = [
type: "object",
properties: [ name: [ type: "string" ], age: [ type: "integer" ] ]
]
person = { "name": "Alice", "age": 30 }
result = json:schema(schema, person)
slog(result)
// => { ok: true, errors: [ ] } if passes
Supports two output types for conversion: Lava <!> JSON and back.
In Lava scripts:
JSON:decode
-- loads string JSON content, returns Lava Value
JSON:encode
-- encodes Lava Value, returns JSON String
Partial and __support handling for all functions with the same placeholder/partial return values as any Lava bridge.
A Lava JSON plugin adds strong functionality, fulfy partial usage, and proper validation according to your doc syntax.