Module json
A simple, compliant JSON parser and serializer for Lily.
Enums
| Value | A value of a valid JSON datatype. |
Exceptions
| JSONSyntaxError | An error in JSON data being parsed. |
Functions
define parse(json: String, comments: *Boolean, trailing_commas: *Boolean, non_finite: *Boolean): Value
Parses JSON data contained in a String into a Value.
lily-json supports some optional extensions to the JSON syntax, which are configurable through keyword arguments (and enabled by default):
comments: Allow// ...and/* ... */comments.trailing_commas: Allow objects and arrays to be closed after commas (eg.{"a": 1, "b": 2, "c": 3,}or[1, 2, 3,]).non_finite: Treat non-finite floating-point values (Infinity,-Infinity, andNaN) as valid numeric literals.
ValueErrorifjsonis empty.JSONSyntaxErrorif the JSON data is invalid.
define parse_file(path: String, comments: *Boolean, trailing_commas: *Boolean, non_finite: *Boolean): Value
Utility function to read and parse JSON data from a file into a Value.
The optional keyword arguments here function identically to parse's.
IOErrorifpathcannot be opened.ValueErrorif the file's contents are not valid UTF-8.ValueErrorif the file is empty.JSONSyntaxErrorif the JSON data is invalid.