Reading Json by position of node

Hi ,

Is there a way to read JSON script by order? Eg: Below is my JSON Script
{
“Workstation_Printer”: {
“Drive”: {
“Status”: 1,
“Value”: "10.188.32.28:Canon_Secure_Blr_01 ",
“StatusDetails”: “Printer is in the same network”
}
},
“Workstation_ScreenLock”: {
“ScreenSaveTimeOut”: {
“Value”: “300”,
“Status”: 1
},
“ScreenSaverIsSecure”: {
“Value”: “1”,
“Status”: 1
},
“ScreenSaveActive”: {
“Value”: “1”,
“Status”: 1
}
},
“Workstation_PasswordPolicy”: {
“Computer role”: {
“Value”: “WORKSTATION”,
“Status”: 1
},
“Length of password history”: {
“Value”: “14”,
“Status”: 1
},
“Minimum password length”: {
“Value”: “8”,
“Status”: 1
},
“Lockout threshold”: {
“Value”: “6”,
“Status”: 1
},
“Lockout duration”: {
“Value”: “720”,
“Status”: 1
},
“Maximum password age”: {
“Value”: “90”,
“Status”: 1
},
“Force user logoff”: {
“Value”: “0”,
“Status”: 1
},
“Minimum password age”: {
“Value”: “1”,
“Status”: 1
},
“Lockout observation window”: {
“Value”: “30”,
“Status”: 1
}
},
“Workstation_Wifi”: {
“Drive”: {
“Value”: “Up”,
“Status”: 0
}
},

IS there a way to get Main Node 1 = Workstation printer, Main Node 2 = Workstation_ScreenLock ,so on…
So my requirement is retrieve the node by passing a number.

Instead of sending the numbers, you can pass the Root node name directly so that you can get the required value easily. I’m trying to create a workflow as you require, will send it once done.

The problem is that, if we have array instead of the JSON object, it will be easy
Let me know if passing the root element name solves your issue or satisfies your requirement

Others may confirm but I believe in this case you need to reference the first nodes by name. For example, to access the value of “minimum password age” and output to a string you need to use the following (JObject should be the name of your JSON):

MinPwdAge = JObject("Minimum password age”)(0)(“Value”).ToString

I am able to get the required values by passing the Root node name. But my requirement is I want to get it by passing a number. Root node may change tomo. So i cant hard code it straight away.

One option then is to navigate using the JObject class and the Next property.

Combined with a for each loop you could iterate through each of the JTokens in the Object. There may be an easier way but you can certainly consider these

Hi Ronan, /
Can you please share the XAML file for the approach that you mentioned(J Tokens)? It will be very helpful.

Hi,
what about this:
JObject.Root.Children.ToArray(1).ToString

Cheers

2 Likes