JSONPath SelectToken Problem

MarHanMarHan Member Posts: 34
Hi community,

I'm struggling in JSON parsing :s - I have the following JSON
{
	"properties": {
		"cmis:creationDate": {
			"cardinality": "single",
			"id": "cmis:creationDate",
			"type": "datetime",
			"value": 1673529791000
		},
		"cmis:name": {
			"cardinality": "single",
			"id": "cmis:name",
			"type": "string",
			"value": ""
		},
		"cmis:objectId": {
			"cardinality": "single",
			"id": "cmis:objectId",
			"type": "id",
			"value": "T000007158"
		}
	}
}

As the "properties" objects could always be different, I first want to create a list of all properties in the JSON object, like this:
[
  "cmis:creationDate",
  "cmis:name",
  "cmis:objectId"
]

So I tried the "SelectToken"-Method on the JsonObject with the following queries, but without success :'( :
properties.*.id
properties[[id]]
$..id

All of those queries determine the wanted result when using them in online jpath evaluators - only AL throws me an error meaning the SelectToken() methods returns with "false".

Any other idea to try? I don't really want to select the "properties" and then loop over them in a classic way when there's a querying-syntax with jpath.

Thanks in advance

Markus


Best Answer

  • ftorneroftornero Member Posts: 524
    Answer ✓
    Hello @MarHan

    You could use somethinglike this to get the properties and the rest of values, with JSON data in the variable JsText:
                    var
                        Jsobj: JsonObject;
                        JsToken: JsonToken;
                        JsText: Text;
                        keys: List of [Text];
    ----------------------
                            Jsobj.ReadFrom(JsText);
                            Jsobj.Get('properties', JsToken);
                            Jsobj := JsToken.AsObject();
                            keys := Jsobj.Keys;
    

    In the var keys you have all the keys and could loop throught them to get the values that you need.

    Regards

Answers

  • MarHanMarHan Member Posts: 34
    Update - I did further investigations with the following results:

    This one

    fkpzpmjunmnb.png

    is totally bad and results in

    boi0s7pcl2x6.png

    These two
    r5ltp8w03s0q.png
    7j8akmzul35i.png

    Result in the error

    DE: Die dem JSON-Pfad „$..id“ entsprechenden Token enthalten mehr als ein Element.
    EN: The tokens corresponding to the JSON path "$..id" contain more than one element.

    Any suggestions?
  • ftorneroftornero Member Posts: 524
    Answer ✓
    Hello @MarHan

    You could use somethinglike this to get the properties and the rest of values, with JSON data in the variable JsText:
                    var
                        Jsobj: JsonObject;
                        JsToken: JsonToken;
                        JsText: Text;
                        keys: List of [Text];
    ----------------------
                            Jsobj.ReadFrom(JsText);
                            Jsobj.Get('properties', JsToken);
                            Jsobj := JsToken.AsObject();
                            keys := Jsobj.Keys;
    

    In the var keys you have all the keys and could loop throught them to get the values that you need.

    Regards
  • MarHanMarHan Member Posts: 34
    Hi ftornero,

    you're the best <3 , that made my day!

    x0t3gr26cszo.png

    Thanks a lot!

    Regards

    Markus
Sign In or Register to comment.