Pyro

A dynamically-typed, garbage-collected scripting language.

Version 0.19.2

std::json


This module contains utility functions for working with JSON.

Functions

format(json: str, indent: i64 = 2) -> str

Formats a string of JSON. The indent argument specifies the number of spaces per level of indentation.

Panics if json does not contain valid JSON.

from_json(json: buf|str, strict: bool = false) -> map|vec|str|i64|f64|bool|null

Unmarshalls the input JSON.

  • A JSON object is unmarshalled as a map.
  • A JSON array is unmarshalled as a vec.

By default, the parser accepts input JSON containing trailing commas and single-line comments beginning with //. Set strict to true to parse the input in strict mode.

Panics if json does not contain valid JSON.

to_json(arg: any, indent: i64 = 0) -> str

Marshalls the Pyro value arg to JSON, returning the result as a string. The indent argument specifies the number of spaces per level of indentation.

The set of valid input values is:

  • null
  • true
  • false
  • i64
  • f64
  • str
  • A vec or tup containing valid input values.
  • A map containing string keys and valid input values.
  • An object with a :$json() method that returns a string containing JSON.
  • Any object whose public field values can be marshalled as JSON.

Panics if arg cannot be marshalled as JSON.