json-mumu

Crates.iojson-mumu
lib.rsjson-mumu
version0.1.2
created_at2025-08-15 13:10:12.297531+00
updated_at2025-08-16 13:21:41.406386+00
descriptionJSON tools and JSON Schema plugin for the Mumu ecosystem
homepagehttps://lava.nu11.uk
repositoryhttps://gitlab.com/tofo/mumu-json
max_upload_size
id1796735
size97,574
(justifiedmumu)

documentation

README

json-mumu

JSON support for the Lava scripting language — a Rust plugin for data-driven scripting and automation.

Author: Tom Fotheringham & contributors


What is mumu-json?

mumu-json is a plugin that adds JSON parsing, encoding, validation, and JSON Schema support to Lava: a lightweight, embeddable scripting language and runtime written in Rust.

With mumu-json, your Lava scripts get seamless, native JSON handling—essential for automation, configuration, and data transformation.

  • Parse JSON text to Lava values
  • Encode Lava values as JSON strings
  • Validate JSON syntax with error reporting
  • Check data against JSON Schemas

Who is this for?

  • Anyone embedding Lava in a Rust application (for scripting, plugins, or config)
  • Lava/MuMu users needing robust JSON in scripts

Installation

Requires Lava. See lava.nu11.uk.

In this directory:

make
sudo make install

Installs libmumujson.so to /usr/local/lib/.


Getting Started

Enable the plugin in your Lava script:

extend("json")

Examples

Encode a Lava value as JSON

extend("json")
person = [ name: "Alice", age: 30 ]
json_string = json:encode(person)
slog(json_string)
# Output: '{"name":"Alice","age":30}'

Decode JSON to a Lava value

decoded = json:decode('{"name":"Bob","age":25}')
slog(decoded)
# Output: [ name: "Bob", age: 25 ]

Pretty-print JSON

pretty = json:encode([ pretty: true ], person)
slog(pretty)
# Output:
# {
#   "name": "Alice",
#   "age": 30
# }

Validate JSON syntax

is_valid = json:validate('{"ok":42}')
slog(is_valid)  # true

is_valid = json:validate("{ bad: json }")
slog(is_valid)  # false

Get parse errors for invalid JSON

result = json:report("{ bad: json }")
slog(result)
# Output: [ 'expected `:` at line 1 column 7' ]

JSON Schema validation

schema = [
  type: "object",
  properties: [ name: [ type: "string" ], age: [ type: "integer" ] ]
]
person = [ name: "Alice", age: 30 ]
result = json:schema(schema, person)
slog(result)
# Output: [ ok: true, errors: [] ]

Features

  • json:encode([options], value) — encode Lava value to JSON (optionally pretty)
  • json:decode(json_str) — decode JSON string to Lava value
  • json:validate(json_str) — check JSON validity (returns true/false)
  • json:report(json_str) — array of error messages (if any)
  • json:schema(schema, value) — validate value against JSON Schema; returns [ ok: bool, errors: [ ... ] ]
  • All functions support partial application and _ as placeholder.

Contributing

Contributions and bug reports are welcome!
Submit issues or pull requests at https://gitlab.com/tofo/mumu-json.


License

Dual-licensed under MIT and Apache-2.0.

See the LICENSE and NOTICE files for details.

Commit count: 4

cargo fmt