Loading...
 

CX_JSON_OBJECT

CX_JSON_OBJECT

Class hierarchy
Description:

This class represents a JSON object. The elements in the JSON structure can be accessed in the same way as the DDI of a class. Internally, the CX_JSON_OBJECT also generates a DDI so that the fields of the JSON object can be examined and modified in the Object Inspector.

In the JSON object, all subordinate JSON objects and arrays are only references to data structures within the root object.
Example: If the following JSON is given {"name":"charlie", "son":{"name":"jack"}}}, then deliver json Copy(name) and "name" json Call(GetTyped) both the string charlie. The calls json Get(son) and "son" json Call(GetTyped) return a CX_JSON_OBJECT, which contains the JSON section {"name":"jack"} represented. On this object, as on the previous object with Copy(name) the name can be read out.
Alternatively, this can also be done on the root element via an access expression: json Copy(son.name) or "son.name" json Call(GetTyped) .

In comparison to the regular access paths, the identifiers hard, soft & this have no special meaning within the path.
The only special meaning is this at the beginning of an access expression and references the object itself. This special rule is only relevant for CX_JSON_ARRAY because
ary Copy([0])

is invalid and is therefore considered

ary Copy(this[0])

must be written.

Since the CX_JSON_OBJECT and CX_JSON_ARRAY objects obtained from the root node via Get(...) and GetTyped are only references or views, you must always ensure that they are no longer used as soon as the root element becomes invalid. If you want to work on it independently of the root element, the structure must be copied completely into a new root element.
This can be achieved with Copy(...) or CopyTransObject.

173936:
When returning numerical values, 8 decimal places are always returned.

If a non-existent field (here x) is queried, the behaviour is defined as follows:

Call Result
"x" json Call(HasTyped)
0 (FALSE)
"x" json Call(GetTyped)
INVALID
json Type(x)
0
json Get(x)
INVALID
json Copy(x)
INVALID

Code example:
 
Var(person)
CreateTransObject(CX_JSON_OBJECT) -> person //empty JSON object
"Jack" person Put(name)
12 person Put(age) //will be written as String (default type)

person "friend" person Call(PutTyped)//insert person into person itself
"Peter" person Put(friend.name)
13 "friend.age" person Call(PutTyped)

"father" CX_JSON_OBJECT person Call(SetDataType)
CreateTransObject(CX_JSON_OBJECT) person Put(father)
"John" person Put(father.name)
45 "father.age" person Call(PutTyped)

"father.married" CX_BOOLEAN person Call(SetDataType)
TRUE person Put(father.married)

person //-> CX_JSON_OBJECT:
// {
// "name":"Jack",
// "age":"12",
// "friend":
// {
// "name":"Peter",
// "age":13
// },
// "father":
// {
// "name":"John",
// "age":45,
// "married":true
// }
// }

List of methods (MDI)
Function MA* Parameters Return Brief description
ClearDataType
176859
STRING Resets the type of a previously set path back to the default value.
GetKeys
212642
VECTOR〈STRING〉 Returns the names of all fields in this JSON object
GetTyped
168869
STRING ANY Returns the value of an access path (no distinction, as required between Copy/Get)
GetTypedLiteralField
232128
STRINGANYReturns the value of an object field (without path navigation).
HasTyped
170077
STRING TRUE/FALSETRUE if there is a value for the access path.
HasTypedLiteralField
232128
STRINGTRUE/FALSETRUE if there is a value for the field name (without path navigation).
PutTyped
169263
ANY, STRING Sets the value of an access path
PutTypedLiteralField
232128
ANY, STRING Sets the value of an object field (without path navigation)
Remove
232557
STRING Removes the value of an access path
SetDataType STRING, TYPE Sets the type of the specified path for Get/Copy, Put, ...

* MA = Member Access Function
TYPE = type ID of (STRING | INTEGER | CX_NUMERIC | CX_BOOLEAN | CX_JSON_OBJECT | CX_JSON_ARRAY)

Data directory (DDI)
Data field Type Reference class I* Brief description
* * * Dynamic DDI, which corresponds to the data structure of the JSON

* I = Indexable data field

Use in AppsWH
Module Brief description