Module json
Generating and Reading JSON.
json_parse_string and json_parse_file will return an llib object, with maps as ‘simple maps’ (arrays where a string key is followed by a value), and arrays containing values. They will return an error object if they fail. If an array only contains numbers, then they will be unboxed and the result is a simple array of doubles.
json_tostring will convert llib values into JSON format.
This interface also defines convenient constructors for generating dynamic data in the correct form for conversion to JSON:
#ifndef LLIB_NO_VALUE_ABBREV #define VM value_map_of_values #define VMS value_map_of_str #define VI value_int #define VS str_ref #define VF value_float #define VB value_bool #define VA value_array_of_values #define VAS value_array_of_str #endif
This header brings in these abbreviations, unless you explicitly define LLIB_NO_VALUE_ABBREV.
Constructing JSON data then is straightforward (note how primitive values need to be boxed):
PValue v = VM(
    "one",VI(10),
    "two",VM("float",VF(1.2)),
    "three",VA(VI(1),VI(2),VI(3)),
    "four",VB(true)
);
Look at value for boxing support. See test-json.c.
Functions
| json_tostring (v) | convert an llib value rep into a JSON string. | 
json-parse Functions
| json_parse_string (str) | convert a string to JSON data. | 
| json_parse_file (file) | convert a file to JSON data. | 
Functions
- json_tostring (v)
 - 
    convert an llib value rep into a JSON string.
 Lists, Maps, Simple Maps and Arrays are understood as containers.
 Arrays of primitives are properly handled.
    
Parameters:
- v PValue
 
Returns:
- 
           char *
    
 
 
json-parse Functions
- json_parse_string (str)
 - 
    convert a string to JSON data.
 As a special optimization, arrays consisting only of numbers
 will be read in as primitive arrays of 
double.Parameters:
- str const char *
 
Returns:
- 
           PValue
    
 
 - json_parse_file (file)
 - 
    convert a file to JSON data.
    
Parameters:
- file const char *
 
Returns:
- 
           PValue