1json_decode 2 3 SYNOPSIS 4 Parse JSON text into an S-Lang data structure 5 6 USAGE 7 json = json_decode (String_Type text) 8 9 DESCRIPTION 10 The `json_decode' function parses JSON data from the input 11 string, and returns a corresponding S-Lang data structure. 12 JSON values are represented as follows: 13 14 JSON -> S-Lang 15 16 object Struct_Type 17 array List_Type 18 string String_Type or BString_Type 19 number (L)Long_Type or Double_Type 20 `true' UChar_Type ('\1') 21 `false' UChar_Type ('\0') 22 `null' Null_Type 23 24 The S-Lang structure corresponding to a JSON object 25 with duplicate keys has no duplicate field names, 26 but the field value is given by the last JSON value. 27 28 If the input string does not contain valid JSON data, 29 or if numeric values cannot be represented within S-Lang, 30 or if JSON objects and/or arrays are too deeply nested, 31 a `Json_Parse_Error' is thrown. 32 33 SEE ALSO 34 json_encode 35 36-------------------------------------------------------------- 37 38json_encode 39 40 SYNOPSIS 41 Generate JSON text from an S-Lang data structure 42 43 USAGE 44 String_Type text = json_encode (json) 45 46 DESCRIPTION 47 The `json_encode' function generates the JSON text 48 that corresponds to the S_Lang data structure `json'. 49 Valid input types -- i.e., those that generate text 50 that can be parsed by `json_decode' -- are Struct_Type 51 (for JSON objects) and List_Type or Array_Type (for 52 JSON arrays), provided that these containers contain 53 only the following types: 54 55 S-Lang -> JSON 56 57 Struct_Type object 58 List_Type or Array_Type array 59 String_Type or BString_Type string 60 UChar_Type ('\1') `true' 61 UChar_Type ('\0') `false' 62 other non-complex numeric types number 63 Null_Type `null' 64 65 Invalid input causes a `Json_Invalid_Json_Error'. 66 67 Optional whitespace in the output text can be configured 68 by the `pre_nsep', `post_nsep', `pre_vsep', and `post_vsep' 69 qualifiers. (Only strings built from ' ', '\t', '\n', 70 or '\r' are allowed. Other characters are ignored.) 71 If present, all whitespace after the final "\n" 72 in `post_vsep' is considered as extra indentation, 73 which accumulates for nested objects and arrays. 74 75 QUALIFIERS 76 ; pre_nsep=str: whitespace before name separator ':' 77 in objects (default: "") 78 ; post_nsep=str: whitespace after name separator ':' 79 in objects (default: "") 80 ; pre_vsep=str: whitespace before value separator ',' 81 in objects or arrays (default: "") 82 ; post_vsep=str: whitespace after value separator ',', 83 after the opening, and before 84 the closing brackets in objects 85 or arrays (default: "") 86 87 EXAMPLE 88 89 % some whitespace and indentation after separators: 90 json_encode (json; pre_nsep="", post_nsep=" ", 91 pre_vsep="", post_vsep="\n ") 92 93 % yet more whitespace around separators: 94 json_encode (json; pre_nsep=" ", post_nsep=" ", 95 pre_vsep=" ", post_vsep="\n\t") 96 97 98 SEE ALSO 99 json_decode 100 101-------------------------------------------------------------- 102