Converting Json Array to a Variable

uiautomation

#1

Hi, I have followed the tutorials however I am struggling to extract content out of json array to a variable. I am trying to do this with ServiceNow however I had the same issue with “https://api.coinmarketcap.com/v1/ticker/ripple/” using the cmc example, I do a web request writing out to a string variable which I can check with a write line. However after that, if I try to Deserialise the json to a jarray or jobject I get an error option strict on disallows converting from string to int. I am sure I am just messing up the data type but some help would be appreciated.


#2

Hi @Chris_Dornan,

Can you send the error message.

Screenshot

Regards,
Arivu


#3

HI Arivu, Thanks for your assistance.

image


#4

Hi Chris,

Can you please post the workflow? I’ve managed to implement a HTTP request to my own developer instance on ServiceNow with no issues.

The output of my HTTPRequest was to a string, to which I performed a deserialization to produce a JObject.

Cheers!


#5

Hi Ollie, Thanks for your reply, I have changed it to JObject as suggested. Where I am falling flat is converting elements within the json to a variable. This is the rest response.
{“result”:[{“number”:“INC0010010”,“user_input”:“test@gmail.com”,“category”:“Threat Response”,“subcategory”:“SearchAndDestroy”}]}
What I want to do is create a variable for incident number, user input, etc. then use the variable in a powershell command to perform a search and destroy on an office 365 tenant. However I am struggling with the syntax to extract the content out the json to a variable. I am trying to use write line however not getting anywhere. I can post the workflow however it is just going to show an incompetent write line function :grin::grin:


#6

Hey Chris, no such thing as incompetency! We’re all learning here and it took me a solid day of struggling to extract the data. What worked for me to assign the data from servicenow to a local variable was:

Using the Assign function:
variable1 = jsonDocument(“result”)(0)(“variableInServiceNow”).ToString

Is that a similar thing to what you’re trying to do?


#7

Thanks Ollie, That looks like what I need. I will give it a go an let you know.


#8

Genius!!! Thanks that was perfect.


#9

Fantastic! All the best :grinning: