Json object - before fetching value particular key found or not, need bool value


Hi Team, above mentioned api Response, i need to check particular key found or not. If key found the then fetch the value.

Ex. Condition 1 : abcd found - i need True.
abcd not found - i need false value.

Without contains method any possible Way’s there pls share ur solutions.

Thanks

Hi @AJITH_SK

Regards

Not working that method

Hi @AJITH_SK

If possible could you share your Input file

{
“data”:{
“query” : “”,
“hrf” : “”,
“scode” : “1”,
“smsg” : “Successful”,
“status” : null,
“errorcode” : null,
“emsg” : null,

“out_value” : [
{
“abcd” : “1234”,
“omnc” : “0004”,
“star” : “RST”,
“qes” : “avi”,
“aurd” : “R”,
“ors” : “”,
“Ids” : “12674”,

}
]
}
}

Hi @AJITH_SK

Consider the below for the JsonObject

Bool_Var = JObject("data")("out_value")(0).Value(Of String)("abcd") IsNot Nothing

Regards

1 Like

Prototype mini sample data:
grafik

we can use the ContainsKey method from the JOBject:
grafik

OR ( with some constraints) a greedy JSON Path along with SelectTokens and Any()
grafik

it is changing more the case as a different aim makes less required the abcd check or let it be more integrated

Options:


Crosscheck - checking a nonexisting key:

Alternates (more are possible)
grafik
Crosscheck - not present behaviour:
grafik

1 Like

Hey @AJITH_SK
try this:
isKeyFound = jsonObject("data")("out_value")(0).ToObject(Of JObject).ContainsKey("abcd")

Example workflow:

  • Deserialize JSON.
  • Assign isKeyFound
  • If isKeyFound:
    • Then Section -fetches and assigns the value of “abcd” to keyValue
      jsonObject("data")("out_value")(0)("abcd").ToString()
    • Else Section - handles the case where “abcd” does not exist.
1 Like

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