The JSON structure

Synopsis

structure JSON

Interface

datatype value
  = OBJECT of (string * value) list
  | ARRAY of value list
  | NULL
  | BOOL of bool
  | INT of IntInf.int
  | FLOAT of real
  | STRING of string

Description

datatype value = …​

This datatype represents JSON values as trees. The constructors are

OBJECT of (string * value) list

represents a JSON object value; i.e., a list of key-value pairs. Note that the keys should be unique.

ARRAY of value list

represents a JSON array value.

NULL

represents the JSON value "null".

BOOL of bool

represents the JSON values "true" and "false".

INT of IntInf.int

represents JSON integer numbers.

FLOAT of real

represents JSON floating-point numbers.

STRING of string

represents JSON strings, which are assumed to be UTF-8 encoded.

Example

The JSON value

{ "a" : 23,
  "b" : [ false, true ],
  "c" : "hello world"
}

has the following representation using the value datatype:

OBJECT[
  ("a", INT 23),
  ("b", ARRAY[BOOL false, BOOL true]),
  ("c", STRING "hello world")
]