FindMemberPath

FindMemberPath 1:

This method searches for a specific property in a JSON document and returns it. The property is specified according to its path in the document. 0 is returned if no corresponding property is found.

Syntax

METHOD FindMemberPath : SJsonValue
VAR_INPUT
  v      : SJsonValue
END_VAR
VAR_IN_OUT CONSTANT
  member : STRING;
END_VAR

FindMemberPath 2: Return value

Name

Type

FindMemberPath

SJsonValue

FindMemberPath 3: Inputs

Name

Type

v

SJsonValue

FindMemberPath 4:/FindMemberPath 5: Inputs/Outputs

Name

Type

member

STRING

Sample call:

jsonDoc  := fbJson.ParseDocument(sExistingJsonDocument);
jsonProp := fbJson.FindMemberPath(jsonDoc, sPath);

Accessing nested objects works according to the scheme a/b/c, to find a variable in a JSON hierarchy. The call for the variable c of the following JSON document is:

jsonProp := fbJson.FindMemberPath(jsonDoc, 'a/b/c');
{
 "a":{
   "b":{
    "c": 123
       }
     }
}

Support for arrays

The method supports JSON documents with arrays from TwinCAT version >3.1.4024.35. The # character can be used to access elements of an array.

jsonProp := fbJson.FindMemberPath(jsonDoc, '#1/Third#2');
[
  {
  "First": 4
  },
  {
  "Second": 12,
  "Third": [
    1,
    2,
    3
    ],
   "Fourth": {
    "a": true
    }
  },
]

The example call accesses the second element of the outer array (#1), then the third element of the array under the sub-element Third.

Treatment of special cases

Inserting the ~ character provides special treatment within a path. The following table lists the different possibilities.

Expression

Result

Sample

~0

~ is used as a character in the string.

Test/Hello~0123 becomes Test/Hello~123

~1

The expression is replaced by the character /, which is not interpreted as a separator, but as part of the string.

Test/Hello~1123 becomes Test/Hello/123

~2

The expression is replaced by the character # , which is not interpreted as an array index, but as part of the string.

Test/Hello~2123 becomes Test/Hello#123