Structure path
Structure path is similar to a JSON path but designed to work better for our use case. It is primarily used for selecting a subtree of an object. In some cases it is extended to provide the possibility of targeting a write subtree.
Syntax
An empty path always means the root of the object. Navigation is only available inwards and always starts from the root.
Read syntax:
To select a field you have to name it:
fieldName
.To select a field object’s field you have to separate their names by a dot:
rootFieldName.childFieldName
. This is used for inwards navigation.To select an array element you have to index it (starting from 0):
arrayFieldName[0]
. UsingarrayFieldName[7].childFieldNode
also works.
Write syntax:
Read syntax is included as the selected subtree will be modified.
Targeting the root object (using empty path) will modify the whole object just like any other subtree.
Append to an array:
pathToArray[+]
:
In case the write value is another array it will append its elements to the target array’s end.
Value
Target path
Read path
Read value after write
["web", "js"]
tags[+]
tags
["android", "ios", "web", "js"]
In case the write value is not an array that value will be added to the target array’s end.
Value
Target path
Read path
Read value after write
"web"
tags[+]
tags
["android", "ios", "web"]
{"type":"none"}
tags[+]
tags
["android", "ios", "web", {"type":"none"}]
There are more options coming for better array operations.
Behavior
When reading a value from a subtree, the whole subtree is returned. If the selected path does not exist in the source object, null
is returned which means not existing value in StructureObject.
When writing a value to a subtree the target subtree is manipulated. If the target path does not exist, it will be created. This will add or replace values along the target path initialized to be empty except the target path.
Note
When a target array is not big enough or does not exist it will be extended or created and the other indexes will be filled by null
.
Samples
Let’s assume that we are working on an object like the following JSON.
{
"key": "common_ok",
"languages": {
"en": "OK",
"hu": "Rendben"
},
"tags": [
"android",
"ios"
],
"meta": [
{
"key": "MetaKey"
}
]
}
Read
key
:common_ok
(String)languages
:{"en": "OK","hu":"Rendben"}
(Object)languages[0]
: ERRORlanguages.en
:OK
(String)tags
:["android", "ios"]
(Array)tags[0]
:android
(String)comment
:null
(Not existing)comment.en
:null
(Not existing)
Write
Value |
Target path |
Read path |
Read value after write |
---|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Write behaviour with merge
Value |
Target path |
Read path |
Read value after write |
---|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Warning
Array append is not available with merge!