parse_json

Definition: include builtins\json.e
object res = parse_json(string s)
Description: Converts a string representation of a JSON object into an internal form suitable for further processing.

s: should contain a valid string representation of a JSON object.

The result of parsing a JSON string is as follows:
  • Numbers and Strings (without quotes) are held natively
  • An object is held as a sequence with a first element of -1 (JSON_OBJECT), and the rest pairs, the first of which is a string and the second any of these types.
  • An array is held as a sequence with a first element of -2 (JSON_ARRAY), and the rest any of these types.
  • A keyword is held as a sequence with a first element of -3 (JSON_KEYWORD), and one of the strings "true", "false", or "null".
Note the subscript of the first pair in an object, and element in an array, is always [2].

For some valid (and invalid) JSON examples, see demo\rosetta\JSON.exw.

Attempts to parse an invalid JSON string yield {JSON_INVALID}, ie {-4}.
See Also: print_json