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 |
|
JSON value, wraps any JSON element.
-
TokenAt
¶
TokenAt fields are
value |
|
line |
int |
row |
int |
JSON parsing token. Contains token and its position.
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;JsonValue?>)
JV returns json::JsonValue ?
argument |
argument type |
---|---|
v |
table<string; json::JsonValue ?> |
Creates JsonValue out of value.
-
JV
(v: array<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: JsonValue? const)¶
write_json returns string
argument |
argument type |
---|---|
val |
json::JsonValue ? const |
Overload accepting temporary type
-
write_json
(val: JsonValue? const#)
write_json returns string
argument |
argument type |
---|---|
val |
json::JsonValue ? const# |
Overload accepting temporary type
20.4. JSON properties¶
-
set_no_trailing_zeros
(value: bool const)¶
set_no_trailing_zeros returns bool const
argument |
argument type |
---|---|
value |
bool const |
if value is true, then numbers are written without trailing zeros.
-
set_no_empty_arrays
(value: bool const)¶
set_no_empty_arrays returns bool const
argument |
argument type |
---|---|
value |
bool const |
if value is true, then empty arrays are not written at all
-
set_allow_duplicate_keys
(value: bool const)¶
set_allow_duplicate_keys returns bool const
argument |
argument type |
---|---|
value |
bool const |
if value is true, then duplicate keys are allowed in objects. the later key overwrites the earlier one.
20.5. Broken JSON¶
-
try_fixing_broken_json
(bad: string)¶
try_fixing_broken_json returns string
argument |
argument type |
---|---|
bad |
string |
fixes broken json. so far supported 1. “string” + “string” string concatination 2. “text “nested text” text” nested quotes 3. extra , at the end of object or array 4. /uXXXXXX sequences in the middle of white space