mumu-json

Crates.iomumu-json
lib.rsmumu-json
version0.1.0
created_at2025-06-18 05:59:34.104675+00
updated_at2025-06-18 05:59:34.104675+00
descriptionJSON tools and JSON Scheam plugin for the Lava language
homepagehttps://lava.nu11.uk
repositoryhttps://gitlab.com/tofo/mumu-json
max_upload_size
id1716645
size92,823
(rusty-shrimp)

documentation

README

LavaJSON | Lava JSON Plugin for Lava

What is it?

Author: Tom Fotheringham & contributors

This is the "json" bridging plugin for Lava scripts.

Installation

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

Partial, Phasers, and Effects

  • 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)

Schema Validation and Reports

Example: Decoding and encoding with Lava

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)

Input: JSON KeyedArray

Partial application

justOptions1 = json:encode([ pretty: false ]) strValue = justOptions1([ 1, 2, 3 ]) slog(strValue)

Decoding

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

Technical

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

Contributing

Commit count: 4

cargo fmt