Skip to main content

Module json

Module json 

Source
Expand description

JSON interchange functions for the gram codec.

These functions form the stable contract between the Rust gram-codec and native TypeScript/Python implementations. All cross-boundary communication uses the JSON interchange format documented in the data-model spec.

§JSON Interchange Format

The format is an array of AstPattern objects:

[
  {
    "subject": {
      "identity": "alice",
      "labels": ["Person"],
      "properties": { "name": "Alice" }
    },
    "elements": []
  }
]

Property values use mixed serialization:

  • Primitives: native JSON (string, number, boolean)
  • Complex types: tagged objects { "type": "symbol"|"range"|"tagged"|"measurement", ... }

Functions§

ast_to_pattern
Convert an AstPattern back to a native Pattern<Subject>.
gram_parse_to_json
Parse gram notation and return a JSON array string of AstPattern objects.
gram_stringify_from_json
Serialize a JSON array of AstPattern objects back to gram notation.
gram_validate_to_json
Validate gram notation and return an empty string on success, or an error message.