Http request output validation

hi… i have a workflow where i have to validate if my JSON Object variable has keys i want to find. i have the simper workflow screenshot below. could anyone help me with this?

@Tammy1998 -
1- Before performing the desensitization -> get the api response code ( like 200 ) then

I have imported ‘Json.Net’ package to the project
create a jObject variable like (responseJson)
parse and assign (responseJson) the the api response with parse (JObject.Parse(responseRequest))
you can use the responseJson object to retrive/validate the keys.
like responseJSON(“element”)(“elementchild”)

hi i don’t get it. i installed json.net package in the project but i can’t understand the next step i should do.

add ‘json.net’ package to your project.
create a variable - type is jObject (and variable name like responseJson)
parse and assign to (responseJson) the response using JObject.Parse

i am getting this kind of error.

Before parsing can you check is the response is null or empty.
also pls log the response output and verify is that a valid json using online sites like (https://jsonformatter.curiousconcept.com/)

this is the response i get…

pls validate the json string in the provided site and verify. also please trim the response string in parsing
like - JObject.Parse(responseRequest.Trim)

i got this as result.

can you able to share the output json -

TEST CITY.xlsx (40.8 KB) test here api.xaml (8.0 KB)

here are the example workflows

please log the response using log message activity and copy the log data from output window, save it in text file and share it here

Hey @Tammy1998

There is a simplest method to check that particular key exists or not you can do at string level. I mean text string you can do something like this :slight_smile:
it will work too for sure.

test_result is of String Datatype

test_result.Contains(“State”).ToString

or

You can use Jtoken To check particular key exists or not and if exists then you can get value too.

To Check Key Exists or not -

test_output is of JObject Datatype

test_output.SelectTokens("Response.View[0].Result[0].Location.Address.State").Any() //Output - True

To Get Value of a Particular Key -

test_output.SelectToken("Response.View[0].Result[0].Location.Address.State").Value(of String) // Output - National Capital Region

Lemme know if you still have problems…!!

Regards…!!
Aksh

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.