JsonElement
JSON value element
json := JsonParser->Parse("{\"name\": \"John\", \"age\": 30}");
json->Get("name")->GetValue()->PrintLine();
json->Get("age")->GetInt()->PrintLine();
# create JSON programmatically
obj := JsonElement->New(JsonElement->JsonType->OBJECT);
obj->Insert("city", "Oakland");
obj->Insert("zip", 94612);
obj->ToString()->PrintLine();Operations
- New
- Add
- AddChild
- Decode
- Encode
- FindElements
- Get
- GetBool
- GetFloat
- GetInt
- GetNames
- GetString
- GetType
- GetValue
- Has
- Insert
- IsNull
- MatchType
- MatchValue
- Size
- ToFormattedString
- ToString
Add #
Adds an element
method : public : Add(elem:JsonElement) ~ BoolParameters
| Name | Type | Description |
|---|---|---|
| elem | JsonElement | element |
Return
| Type | Description |
|---|---|
| Bool | true if successful, false otherwise |
Example
arr := Data.JSON.JsonElement->New(Data.JSON.JsonElement->JsonType->ARRAY);
item := Data.JSON.JsonElement->New(Data.JSON.JsonElement->JsonType->NUMBER, "42");
arr->Add(item);
arr->Size()->PrintLine(); # 1Add #
Adds a value
method : public : Add(value:String) ~ BoolParameters
| Name | Type | Description |
|---|---|---|
| value | String | value |
Return
| Type | Description |
|---|---|
| Bool | true if successful, false otherwise |
Example
arr := Data.JSON.JsonElement->New(Data.JSON.JsonElement->JsonType->ARRAY);
arr->Add("apple");
arr->Add("banana");
arr->ToString()->PrintLine();Add #
Adds a value
method : public : Add(value:Int) ~ BoolParameters
| Name | Type | Description |
|---|---|---|
| value | Int | value |
Return
| Type | Description |
|---|---|
| Bool | true if successful, false otherwise |
Add #
Adds a value
method : public : Add(value:Float) ~ BoolParameters
| Name | Type | Description |
|---|---|---|
| value | Float | value |
Return
| Type | Description |
|---|---|
| Bool | true if successful, false otherwise |
Add #
Adds a value
method : public : Add(value:Bool) ~ BoolParameters
| Name | Type | Description |
|---|---|---|
| value | Bool | value |
Return
| Type | Description |
|---|---|
| Bool | true if successful, false otherwise |
AddChild #
Adds a class child node
method : public : AddChild(name:String) ~ JsonElementParameters
| Name | Type | Description |
|---|---|---|
| name | String | class name |
Return
| Type | Description |
|---|---|
| JsonElement | child class |
Decode # native
General decoding for Json strings
function : native : Decode(str:String) ~ StringParameters
| Name | Type | Description |
|---|---|---|
| str | String | encoded string |
Return
| Type | Description |
|---|---|
| String | decoded string |
Encode # native
General encoding for JSON strings
function : native : Encode(str:String) ~ StringParameters
| Name | Type | Description |
|---|---|---|
| str | String | decoded string |
Return
| Type | Description |
|---|---|
| String | encoding string |
FindElements #
Queries the object graph. Object attributes referenced by '/' while array elements are referenced by '[index]'. Example "cars/[last]/make".
method : public : FindElements(path:String) ~ JsonElementParameters
| Name | Type | Description |
|---|---|---|
| path | String | query path |
Return
| Type | Description |
|---|---|
| JsonElement | matching element |
Example
json := Data.JSON.JsonParser->TextToElement("{\"users\":[{\"name\":\"Alice\"},{\"name\":\"Bob\"}]}");
alice := json->FindElements("users/[0]/name");
alice->GetString()->PrintLine(); # AliceGet #
Gets an indexed value from an array type
method : public : Get(index:Int) ~ JsonElementParameters
| Name | Type | Description |
|---|---|---|
| index | Int | index |
Return
| Type | Description |
|---|---|
| JsonElement | indexed value |
Example
arr := Data.JSON.JsonParser->TextToElement("[10,20,30]");
arr->Get(1)->GetInt()->PrintLine(); # 20Get #
Gets a named value from an object type
method : public : Get(name:String) ~ JsonElementParameters
| Name | Type | Description |
|---|---|---|
| name | String | element name |
Return
| Type | Description |
|---|---|
| JsonElement | element value |
Example
obj := Data.JSON.JsonParser->TextToElement("{\"x\":42}");
obj->Get("x")->GetInt()->PrintLine(); # 42GetBool #
Gets the float value
method : public : GetBool() ~ BoolReturn
| Type | Description |
|---|---|
| Bool | float value |
Example
root := Data.JSON.JsonParser->TextToElement("{\"active\":true}");
root->Get("active")->GetBool()->PrintLine(); # trueGetFloat #
Gets the float value
method : public : GetFloat() ~ FloatReturn
| Type | Description |
|---|---|
| Float | float value |
Example
root := Data.JSON.JsonParser->TextToElement("{\"pi\":3.14}");
root->Get("pi")->GetFloat()->PrintLine(); # 3.14GetInt #
Gets the integer value
method : public : GetInt() ~ IntReturn
| Type | Description |
|---|---|
| Int | integer value |
Example
root := Data.JSON.JsonParser->TextToElement("{\"port\":8080}");
root->Get("port")->GetInt()->PrintLine(); # 8080GetNames #
Gets the names of object attributes
method : public : GetNames() ~ Vector<String>Return
| Type | Description |
|---|---|
| Vector<String> | object attribute names |
GetString #
Gets the string value
method : public : GetString() ~ StringReturn
| Type | Description |
|---|---|
| String | string value |
Example
root := Data.JSON.JsonParser->TextToElement("{\"city\":\"Oakland\"}");
root->Get("city")->GetString()->PrintLine(); # OaklandGetType #
Gets the type
method : public : GetType() ~ JsonElement->JsonTypeReturn
| Type | Description |
|---|---|
| JsonElement->JsonType | type |
Example
elem := Data.JSON.JsonParser->TextToElement("42");
if(elem->GetType() = Data.JSON.JsonElement->JsonType->NUMBER) {
"Is number"->PrintLine();
};GetValue #
Gets the string value
method : public : GetValue() ~ StringReturn
| Type | Description |
|---|---|
| String | string value |
Example
elem := Data.JSON.JsonParser->TextToElement("\"hello\"");
elem->GetValue()->PrintLine(); # helloHas #
Check to see if the indexed value exists
method : public : Has(index:Int) ~ BoolParameters
| Name | Type | Description |
|---|---|---|
| index | Int | index |
Return
| Type | Description |
|---|---|
| Bool | true if exists, false otherwise |
Has #
Check to see if the indexed value exists
method : public : Has(name:String) ~ BoolParameters
| Name | Type | Description |
|---|---|---|
| name | String | element name |
Return
| Type | Description |
|---|---|
| Bool | true if exists, false otherwise |
Insert #
Insert an element
method : public : Insert(name:String, elem:JsonElement) ~ BoolParameters
| Name | Type | Description |
|---|---|---|
| name | String | element name |
| elem | JsonElement | element |
Return
| Type | Description |
|---|---|
| Bool | true if successful, false otherwise |
Insert #
Inserts a value
method : public : Insert(name:String, value:String) ~ BoolParameters
| Name | Type | Description |
|---|---|---|
| name | String | value name |
| value | String | value |
Return
| Type | Description |
|---|---|
| Bool | true if successful, false otherwise |
Example
obj := Data.JSON.JsonElement->New(Data.JSON.JsonElement->JsonType->OBJECT);
obj->Insert("lang", "Objeck");
obj->Insert("version", "2026");
obj->ToString()->PrintLine();Insert #
Inserts a value
method : public : Insert(name:String, value:Int) ~ BoolParameters
| Name | Type | Description |
|---|---|---|
| name | String | value name |
| value | Int | value |
Return
| Type | Description |
|---|---|
| Bool | true if successful, false otherwise |
Insert #
Inserts a value
method : public : Insert(name:String, value:Float) ~ BoolParameters
| Name | Type | Description |
|---|---|---|
| name | String | value name |
| value | Float | value |
Return
| Type | Description |
|---|---|
| Bool | true if successful, false otherwise |
Insert #
Inserts a value
method : public : Insert(name:String, value:Bool) ~ BoolParameters
| Name | Type | Description |
|---|---|---|
| name | String | value name |
| value | Bool | value |
Return
| Type | Description |
|---|---|
| Bool | true if successful, false otherwise |
IsNull #
Checks for 'null' JSON value
method : public : IsNull() ~ BoolReturn
| Type | Description |
|---|---|
| Bool | true if 'null', false otherwise |
Example
elem := Data.JSON.JsonParser->TextToElement("null");
if(elem->IsNull()) {
"Null value"->PrintLine();
};IsNull # function
Checks for 'null' JSON value
function : IsNull(elem:JsonElement) ~ BoolParameters
| Name | Type | Description |
|---|---|---|
| elem | JsonElement | element to check |
Return
| Type | Description |
|---|---|
| Bool | true if 'null', false otherwise |
MatchType # function
Checks a node's type
function : MatchType(elem:JsonElement, type:JsonElement->JsonType) ~ BoolParameters
| Name | Type | Description |
|---|---|---|
| elem | JsonElement | element to check |
| type | JsonElement->JsonType | type to check |
Return
| Type | Description |
|---|---|
| Bool | true of matching, false otherwise |
MatchValue # function
Checks a node's type
function : MatchValue(elem:JsonElement, value:String) ~ BoolParameters
| Name | Type | Description |
|---|---|---|
| elem | JsonElement | element to check |
| value | String | value to check |
Return
| Type | Description |
|---|---|
| Bool | true of matching, false otherwise |
New # constructor
Constructor
New(type:JsonElement->JsonType)Parameters
| Name | Type | Description |
|---|---|---|
| type | JsonElement->JsonType | Json element type |
New # constructor
Constructor
New(type:JsonElement->JsonType, value:String)Parameters
| Name | Type | Description |
|---|---|---|
| type | JsonElement->JsonType | Json element type |
| value | String | Json string value |
New # constructor
Constructor
New(value:String)Parameters
| Name | Type | Description |
|---|---|---|
| value | String | Json string value |
New # constructor
Constructor
New(array_elems:Vector<JsonElement>)Parameters
| Name | Type | Description |
|---|---|---|
| array_elems | Vector<JsonElement> | Json array value |
New # constructor
Constructor
New(map_elems:Map<String,JsonElement>)Parameters
| Name | Type | Description |
|---|---|---|
| map_elems | Map<String,JsonElement> | Json object (names/values) |
Size #
Gets the size of an array or object value
method : public : Size() ~ IntReturn
| Type | Description |
|---|---|
| Int | size of an array or object value |
Example
arr := Data.JSON.JsonParser->TextToElement("[1,2,3,4,5]");
arr->Size()->PrintLine(); # 5