Read json

Purpose: Read data elements of JSON document.

 read-json <json> \
     [ key <key> ] \
     [ value <value> ] \
     [ type <type> ] \
     [ next ]

read-json reads data elements from <json> variable, which is created with json-doc. A data element is a string <key>/<value> pair of a leaf node, where key (in "key" clause) is a normalized key name, which is the value's name preceded with the names of all objects and array members leading up to it, separated by a dot (".").

The actual <value> is obtained with "value" clause, and the <type> of value can be obtained with "type" clause.

<type> is a number that can be GG_JSON_TYPE_STRING, GG_JSON_TYPE_NUMBER, GG_JSON_TYPE_REAL, GG_JSON_TYPE_BOOL and GG_JSON_TYPE_NULL for string, number, real (floating point), boolean and null values respectively. Note that <value> is always a string representation of these types.

Use "next" clause to move to the next sequential key/value pair in the document, from top down. Typically, you would get a key first, examine if it's of interest to you, and then obtain value. This is because Gliimly uses "lazy" approach where value is not copied until needed; with this approach JSON parsing is faster.

If there are no more data elements to read, <type> is GG_JSON_TYPE_NONE.

<key> in "key" clause is a normalized name of any given leaf node in JSON text. This means every non-leaf node is included (such as arrays and objects), separated by a dot ("."), and arrays are indexed with "[]". An example would be:
 "menu"."popup"."menuitem"[1]."onclick"

Examples
See json-doc.
See also
JSON parsing
json-doc  
read-json  
See all
documentation


Copyright (c) 2019-2024 Gliim LLC. All contents on this web site is "AS IS" without warranties or guarantees of any kind.