20. JSON manipulation library

The JSON module implements JSON parser and serialization routines. See JHSON <www.json.org> for details.

All functions and symbols are in “json” module, use require to get access to it.

require daslib/json

20.1. Type aliases

JsValue is a variant type

_object

table<string;JsonValue?>

_array

array<JsonValue?>

_string

string

_number

double

_bool

bool

_null

void?

Single JSON element.

Token is a variant type

_string

string

_number

double

_bool

bool

_null

void?

_symbol

int

_error

string

JSON input stream token.

JsonValue

JsonValue fields are

value

JsValue

JSON value, wraps any JSON element.

20.2. Value conversion

JV(v: string const)

JV returns json::JsonValue ?

argument

argument type

v

string const

Creates JsonValue out of value.

JV(v: double const)

JV returns json::JsonValue ?

argument

argument type

v

double const

Creates JsonValue out of value.

JV(v: bool const)

JV returns json::JsonValue ?

argument

argument type

v

bool const

Creates JsonValue out of value.

JVNull()

JVNull returns json::JsonValue ?

Creates JsonValue representing null.

JV(v: table<string;json::JsonValue?>)

JV returns json::JsonValue ?

argument

argument type

v

table<string; json::JsonValue ?>

Creates JsonValue out of value.

JV(v: array<json::JsonValue?>)

JV returns json::JsonValue ?

argument

argument type

v

array< json::JsonValue ?>

Creates JsonValue out of value.

20.3. Read and write

read_json(text: string const implicit; error: string&)

read_json returns json::JsonValue ?

argument

argument type

text

string const implicit

error

string&

reads JSON from the text string. if error is not empty, it contains the parsing error message.

read_json(text: array<uint8> const; error: string&)

read_json returns json::JsonValue ?

argument

argument type

text

array<uint8> const

error

string&

reads JSON from the text string. if error is not empty, it contains the parsing error message.

write_json(val: json::JsonValue? const)

write_json returns string

argument

argument type

val

json::JsonValue ? const

returns JSON (textual) representation of JsonValue as a string.