Libraries |
|
JSON | Source Code |
|
|
Types | ||||
| ||||
|
jsonCategory
const type: jsonCategory
-
Enumeration type describing the category of a jsonValue. Categories are JSON_NULL, JSON_BOOLEAN, JSON_NUMBER, JSON_STRING, JSON_ARRAY and JSON_OBJECT.
jsonValue
const type: jsonValue
-
Interface type to represent JSON values. JSON values can be null (jsonNull), booleans (jsonBoolean), numbers (jsonNumber), strings (jsonString), arrays (jsonArray) or objects (jsonObject).
var jsonValue: json is jsonValue.value; ... json := readJson("{\"size\": 2, \"keys\": [{\"id\": 1}, {\"id\": 2}]"); if "keys" in json and category(json["keys"]) = JSON_ARRAY then for aKey range json["keys"] do write(integer(aKey["id"]) <& " "); end for; writeln; end if;
Operator Summary | |||||
jsonValue |
| ||||
jsonValue |
| ||||
boolean |
| ||||
boolean |
|
Function Summary | |||||
jsonCategory |
| ||||
type |
| ||||
void |
| ||||
boolean |
| ||||
integer |
| ||||
bigInteger |
| ||||
float |
| ||||
string |
| ||||
integer |
| ||||
integer |
| ||||
integer |
| ||||
array string |
| ||||
array jsonValue |
| ||||
string |
| ||||
void |
| ||||
jsonValue |
| ||||
jsonValue |
| ||||
jsonValue |
| ||||
jsonValue |
| ||||
jsonValue |
| ||||
jsonValue |
| ||||
jsonValue |
| ||||
jsonValue |
| ||||
jsonValue |
| ||||
jsonValue |
|
Operator Detail |
[
const func jsonValue: (in jsonValue: aValue) [ (in integer: index) ]
-
Access one element from the JSON array aValue.
type( readJson("[false, 0.125]")[1]) returns boolean boolean(readJson("[false, 0.125]")[1]) returns FALSE type( readJson("[false, 0.125]")[2]) returns float float( readJson("[false, 0.125]")[2]) returns 0.125
- Returns:
- the element with the specified index from aValue.
- Raises:
- INDEX_ERROR - If index is less than 1 or greater than maxIdx(aValue).
- ILLEGAL_ACTION - The value aValue is not a JSON array.
[
const func jsonValue: (in jsonValue: aValue) [ (in string: name) ]
-
Access one element from the JSON object aValue.
type( readJson("{\"fee\": 0.5, \"foo\": true}")["fee"]) returns float float( readJson("{\"fee\": 0.5, \"foo\": true}")["fee"]) returns 0.5 type( readJson("{\"fee\": 0.5, \"foo\": true}")["foo"]) returns boolean boolean(readJson("{\"fee\": 0.5, \"foo\": true}")["foo"]) returns TRUE
- Returns:
- the element with the specified name from aValue.
- Raises:
- INDEX_ERROR - If aValue does not have an element with the key name.
- ILLEGAL_ACTION - The value aValue is not a JSON object.
in
const func boolean: (in string: aKey) in (in jsonValue: aValue)
-
Determine if aKey is an element name of the JSON object aValue.
"fee" in readJson("{\"fee\": 0.5, \"foo\": true}") returns TRUE "fi" in readJson("{\"fee\": 0.5, \"foo\": true}") returns FALSE
- Returns:
- TRUE if aKey is an element name of the JSON object aValue, FALSE otherwise.
not in
const func boolean: (in string: aKey) not in (in jsonValue: aValue)
-
Determine if aKey is not an element name of the JSON object aValue.
"fee" not in readJson("{\"fee\": 0.5, \"foo\": true}") returns FALSE "fi" not in readJson("{\"fee\": 0.5, \"foo\": true}") returns TRUE
- Returns:
- FALSE if aKey is an element name of the JSON object aValue, TRUE otherwise.
Function Detail |
category
const func jsonCategory: category (in jsonValue: aValue)
-
Get the category of the JSON value aValue. Returns one of JSON_NULL, JSON_BOOLEAN, JSON_NUMBER, JSON_STRING, JSON_ARRAY or JSON_OBJECT.
category(jsonValue(NULL)) returns JSON_NULL category(jsonValue(TRUE)) returns JSON_BOOLEAN category(jsonValue( 12345 )) returns JSON_NUMBER category(jsonValue(9223372036854775808_)) returns JSON_NUMBER category(jsonValue("foo")) returns JSON_STRING category(readJson("false")) returns JSON_BOOLEAN category(readJson("9223372036854775808")) returns JSON_NUMBER category(readJson("0.00000762939453125")) returns JSON_NUMBER
- Returns:
- the category of the JSON value aValue.
type
const func type: type (in jsonValue: aValue)
-
Get the type of the JSON value aValue. Returns one of void, boolean, integer, bigInteger, float, string, jsonValueArray or jsonValueMap.
type(jsonValue(NULL)) returns void type(jsonValue(TRUE)) returns boolean type(jsonValue(9223372036854775808_)) returns bigInteger type(jsonValue(0.00000762939453125 )) returns float type(jsonValue("foo")) returns string type(readJson("false")) returns boolean type(readJson("9223372036854775808")) returns bigInteger type(readJson("0.00000762939453125")) returns float
- Returns:
- the type of the JSON value aValue.
void
const func void: void (in jsonValue: aValue)
-
Get the void value from the JSON null aValue. This function is defined for completeness. If applied on a JSON null it will always return empty.
void(jsonValue(NULL)) returns empty void(readJson("null")) returns empty
The function type can be used to check for JSON null:
if type(aJasonValue) = void then
The function category can be used for the same purpose:
if category(aJasonValue) = JSON_NULL then
- Returns:
- the void value of a JSON null.
- Raises:
- ILLEGAL_ACTION - The value aValue is not a JSON null.
boolean
const func boolean: boolean (in jsonValue: aValue)
-
Get the boolean value from the JSON boolean aValue.
boolean(jsonValue(FALSE)) returns FALSE boolean(readJson("true")) returns TRUE
The function type can be used to check for a boolean:
if type(aJasonValue) = boolean then aBoolean := boolean(aJasonValue);
The function category can be used for the same purpose:
if category(aJasonValue) = JSON_BOOLEAN then aBoolean := boolean(aJasonValue);
- Returns:
- the boolean value of a JSON boolean.
- Raises:
- ILLEGAL_ACTION - The value aValue is not a JSON boolean.
integer
const func integer: integer (in jsonValue: aValue)
-
Get the integer value from the JSON number aValue.
integer(jsonValue(12345)) returns 12345 integer(readJson("12345")) returns 12345 integer(readJson("12345678909876543210")) raises RANGE_ERROR
The function type can be used to check for an integer:
if type(aJasonValue) = integer then anInteger := integer(aJasonValue);
- Returns:
- the integer value of a JSON number.
- Raises:
- ILLEGAL_ACTION - The value aValue is not a JSON number.
- RANGE_ERROR - The JSON number cannot be represented as integer.
bigInteger
const func bigInteger: bigInteger (in jsonValue: aValue)
-
Get the bigInteger value from the JSON number aValue.
bigInteger(jsonValue(12345_)) returns 12345_ bigInteger(readJson("12345")) returns 12345_ bigInteger(readJson("123.45")) raises RANGE_ERROR
The function type can be used to check for a bigInteger:
if type(aJasonValue) = bigInteger then aBigInteger := bigInteger(aJasonValue);
- Returns:
- the bigInteger value of a JSON number.
- Raises:
- ILLEGAL_ACTION - The value aValue is not a JSON number.
- RANGE_ERROR - The JSON number cannot be represented as bigInteger.
float
const func float: float (in jsonValue: aValue)
-
Get the float value from the JSON number aValue.
float(jsonValue(0.0625)) returns 0.0625 float(readJson("0.0625")) returns 0.0625
The function type can be used to check for a float:
if type(aJasonValue) = float then aFloat := float(aJasonValue);
- Returns:
- the float value of a JSON number.
- Raises:
- ILLEGAL_ACTION - The value aValue is not a JSON number.
string
const func string: string (in jsonValue: aValue)
-
Get the string value from the JSON string aValue.
string(jsonValue("")) returns "" string(jsonValue("abcdefg")) returns "abcdefg" string(jsonValue(" \t\r\n")) returns " \t\r\n" string(readJson("\"\"")) returns "" string(readJson("\"abcdefg\"")) returns "abcdefg" string(readJson("\" \\t\\r\\n\"")) returns " \t\r\n"
The function type can be used to check for a string:
if type(aJasonValue) = string then aString := string(aJasonValue);
The function category can be used for the same purpose:
if category(aJasonValue) = JSON_STRING then aString := string(aJasonValue);
- Returns:
- the string value of a JSON string.
- Raises:
- ILLEGAL_ACTION - The value aValue is not a JSON string.
length
const func integer: length (in jsonValue: aValue)
-
Length of JSON array aValue.
length(readJson("[]")) returns 0 length(readJson("[1]")) returns 1 length(readJson("[1, \"foo\"]")) returns 2
- Returns:
- the length of the JSON array.
- Raises:
- ILLEGAL_ACTION - The value aValue is not a JSON array.
minIdx
const func integer: minIdx (in jsonValue: aValue)
-
Minimum index of JSON array aValue.
minIdx(readJson("[]")) returns 1 minIdx(readJson("[1]")) returns 1 minIdx(readJson("[1, \"foo\"]")) returns 1
- Returns:
- the minimum index of the JSON array.
- Raises:
- ILLEGAL_ACTION - The value aValue is not a JSON array.
maxIdx
const func integer: maxIdx (in jsonValue: aValue)
-
Maximum index of JSON array aValue.
maxIdx(readJson("[]")) returns 0 maxIdx(readJson("[1]")) returns 1 maxIdx(readJson("[1, \"foo\"]")) returns 2
- Returns:
- the maximum index of the JSON array.
- Raises:
- ILLEGAL_ACTION - The value aValue is not a JSON array.
keys
const func array string: keys (in jsonValue: aValue)
-
Obtain the element names of the JSON object aValue.
keys(readJson("{}")) returns 0 times "" keys(readJson("{\"fee\": 0.5}")) returns [] ("fee") keys(readJson("{\"fee\": 0.5, \"foo\": true}")) returns [] ("fee", "foo")
- Returns:
- an array with the element names of the JSON object.
- Raises:
- ILLEGAL_ACTION - The value aValue is not a JSON object.
values
const func array jsonValue: values (in jsonValue: aValue)
-
Obtain the elements of the JSON array aValue.
values(readJson("[]")) returns 0 times jsonValue.value values(readJson("[\"fee\"]")) returns [] (jsonValue("fee")) values(readJson("[0.5, true]")) returns [] (jsonValue(0.5), jsonValue(TRUE))
- Returns:
- an array with the elements of the JSON array.
- Raises:
- ILLEGAL_ACTION - The value aValue is not a JSON array.
str
const func string: str (in jsonValue: aValue)
for
const proc: for (inout jsonValue: forVar) range (in jsonValue: aValue) do (in proc: statements) end for
-
For-loop where forVar loops over the elements of a JSON array.
var jsonValue: json is jsonValue.value; var jsonValue: anElement is jsonValue.value; ... if "keys" in json and category(json["keys"]) = JSON_ARRAY then for anElement range json["keys"] do ...
jsonValue
const func jsonValue: jsonValue (NULL)
jsonValue
const func jsonValue: jsonValue (in boolean: okay)
jsonNumber
const func jsonValue: jsonNumber (in string: number)
-
Create a jsonNumber with the given number.
jsonValue
const func jsonValue: jsonValue (in integer: number)
jsonValue
const func jsonValue: jsonValue (in bigInteger: number)
-
Create a jsonValue with the given bigInteger number.
jsonValue(123_)
- Returns:
- a jsonNumber with the given bigInteger number as jsonValue.
jsonValue
const func jsonValue: jsonValue (in float: number)
jsonValue
const func jsonValue: jsonValue (in string: stri)
jsonValue
const func jsonValue: jsonValue (in jsonValueArray: elements)
readJson
const func jsonValue: readJson (inout file: inFile)
-
Read a jsonValue from the given inFile.
var file: aFile is STD_NULL; var jsonValue: json is jsonValue.value; ... aFile := openUtf8("test.json", "r"); if aFile <> STD_NULL then json := readJson(aFile);
- Returns:
- the jsonValue read from inFile.
- Raises:
- RANGE_ERROR - The inFile does not contain valid JSON.
readJson
const func jsonValue: readJson (in string: jsonStri)
|
|