postwick
(Paul Ostwick)
June 7, 2022, 8:07pm
1
I know there are tons of JSON threads here, but I’m beating my head against the wall here. Say I have this JSON:
{
"Sheet1": {
"Columns": {
"Column1": "Name",
"Column2": "Age"
},
"StartingCell": "A1",
"Filter": "[Name] = 'Paul'",
"UseHeaders": "No"
},
"Sheet2": {
"Columns": {
"Column1": "Name",
"Column2": "Age"
},
"StartingCell": "A5",
"Filter": "[Name] = 'Mary'",
"UseHeaders": "No"
}
}
I want to be able to
Loop through the top level objects (ie Sheet1, Sheet2)
** Get Columns as a Dictionary so I can loop through it later
** Get the string values of StartingCell, Filter, and UseHeaders
It seems like this SHOULD be somewhat easy, but I just don’t understand JSON well enough.
ppr
(Peter Preuss)
June 7, 2022, 8:51pm
2
Preperation:
Lets loop over the top level properties: myJObject.Properties
Access name / value from the property
lets use a deserialize to convert it directly to the dict:
while looping we can access as usually from looped item like:
(“KeyName”).Value(of String)
SelectToken Method
Kindly note: Prototype statements are for demo purpose and can be decomposed to essential activities like for each, assign…
ppr
(Peter Preuss)
June 7, 2022, 9:15pm
4
postwick:
how do I get the top level name during the loop - ie Sheet1, Sheet2, etc?
As shown here:
And also:
For each activity: item in myJObject.Properties | TypeArgument: JProperty
Assign Activity: prpName = item.Name
postwick
(Paul Ostwick)
June 7, 2022, 9:21pm
5
Yeah I deleted my reply because I saw it after asking
This was very helpful. It was the .properties and .value stuff I didn’t know.
postwick
(Paul Ostwick)
June 7, 2022, 9:28pm
6
For others, @ppr gave me the clues I needed, and this is how I used activities to get what I want:
Looping through each sheet and getting the simple values:
The rest of the For Each where I get the Columns dictionary and loop through it…
The output:
system
(system)
Closed
June 10, 2022, 9:29pm
7
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.