JSONPath SelectToken Problem

MarHan
Member Posts: 34
Hi community,
I'm struggling in JSON parsing
- I have the following JSON
As the "properties" objects could always be different, I first want to create a list of all properties in the JSON object, like this:
So I tried the "SelectToken"-Method on the JsonObject with the following queries, but without success
:
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
I'm struggling in JSON parsing

{ "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
0
Best 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.
Regards0
Answers
-
Update - I did further investigations with the following results:
This one
is totally bad and results in
These two
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?0 -
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.
Regards0 -
Hi ftornero,
you're the best, that made my day!
Thanks a lot!
Regards
Markus0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions