I am looking to extract several values in a JSON-object, perhaps by using a wildcard if possible.
The placement of the values is based on another key on the same level.
Based on the image below, I want to extract all tokens called “document-1”, “document-2” etc.
I always know that they are situated in the JSON where identifier = ElementUpload.
Before extracting/looping the “document”-keys, I want to make a .Count to check if they are present at all.
But, when counting/filtering the only document-X JTokens we may touch a limit at the JSON Path. (looks like we cannot touch the property name with a JSONPath function used within a filter expression. But it is not confirmed and maybe technically possible when involving keys() and regex?)
Here would LINQ help and can be involved within a hybrid mode:
I went with your .Count approach and in my For Each …values.* I simply have an If-activity to check whether currentvalue.Path.Contains(“values.document-”).
Perhaps not the prettiest solution I came up with, but it works
Assign int_NumberOfDocuments = jobj_Blanketdata.SelectTokens("..[?(@.identifier == 'ElementUpload')].values.*").Count(function (x) x.Parent.Value(Of JProperty).Name.startswith("document-"))
If int_NumberOfDocuments > 0
For Each jobj_Blanketdata.SelectTokens("..[?(@.identifier == 'ElementUpload')].values.*") as currentvalue
If currentvalue.Path.Contains("values.document-")
Add currentvalue to list_DocsForExtraction
Perfect, also have a look at this variation as mentioned on:
myLKDict | Dictionary(Of String, String) =
(From jt In myJOBject.SelectTokens("..[?(@.identifier == 'ElementUpload')].values")
From pr In jt.Value(Of JObject).Properties()
Where pr.Name.toUpper().StartsWith("DOCUMENT-")
Select r=pr).ToDictionary(Function (x) x.Name, Function (x) x.Value.Value(Of String))