Skip to main content

Module json

Module json 

Source
Expand description

JSON output that matches pi’s JSON.stringify.

serde_json and JavaScript escape strings the same way but print numbers differently: JavaScript writes 0.000003 and 5 where serde_json writes 3e-6 and 5.0. These functions print numbers the JavaScript way, so a document parsed from a pi file serializes back to the same bytes.

Traits§

JsonValue
A JSON document in memory, whose serialization cannot fail.

Functions§

js_number
JavaScript’s Number(text): surrounding whitespace ignored, 0 for empty text, unsigned 0x, 0o and 0b integers, Infinity with an optional sign, else a decimal literal, and NaN for anything else.
number
A JavaScript number as JSON: an integer when it is a safe one, so it compares equal to the same number parsed from a pi file.
parse
Parses text like pi’s JSON.parse(stripBom(text)): a leading byte order mark is ignored.
stringify
Serializes a JSON value like JSON.stringify(value).
to_string
Serializes value like JSON.stringify(value).
to_string_pretty
Serializes value like JSON.stringify(value, null, indent).