std::json
This module contains utility functions for working with JSON.
Functions
-
format(json: str, indent: i64 = 2) -> str|err -
Formats a string of JSON. The
indentargument specifies the number of spaces per level of indentation.Returns an
errifjsonis not valid JSON. -
from_json(json: str) -> map|vec|str|i64|f64|bool|null|err -
Unmarshalls the input JSON string.
-
A JSON object is unmarshalled as a
map. -
A JSON array is unmarshalled as a
vec. -
Supports input with trailing commas and single-line comments beginning with
//.
Returns an
errifargisn't a valid JSON string. -
A JSON object is unmarshalled as a
-
to_json(arg: any, indent: i64 = 0) -> str|err -
Marshalls the Pyro value
argto JSON, returning the result as a string. Theindentargument specifies the number of spaces per level of indentation.The set of valid input values is:
-
null -
true -
false -
i64 -
f64 -
str -
A
vecortupcontaining valid values. -
A
mapcontaining string keys and valid values. -
An object with a
:$json()method that returns a string containing JSON. - Any object whose public field values can be marshalled as JSON.
Note that this function does not check for cycles in the input, e.g. a
vecthat contains itself.Returns an
errifargcannot be marshalled as JSON. -