Check for Key in Hierarchical Json

Hello!

I am trying to confirm if a specific key exists in a hierarchical Json like below;

{
“Assignments”: [
{
“id”: “14332”,
“type”: “page”,
“status”: “current”,
“title”: “1.1.1.1”,
“macroRenderedOutput”: {},
“body”: {
“storage”: {
“value”: "<ac:structured-macro ac:name=“details”
},

I know the first level of keys are able to be checked by using ContainsKey method.
(e.g .ContainsKey(“assignments”) can use to check if the “body” key exists in above Json and it would respond “true”)
For instance I would want to check if “Value” exists, but I can’t find a way of going further into the individual keys.

1 Like

Hi,

Have you ever tried something like:

jsonFile("Assignments")(0)("body")("storage")("value")

This may help, thank you, the problem I have is there is a part of my code that says
If item(“body”).toString = nothing then
The code will then either leave it if it has “body” or write 2there is no body" if the key is empty.
The problem is with Json, is the value will never be nothing, the key simply won’t appear, I need a way mark it as not existing for example with a boolean then add the line “body” and leave it empty.

1 Like

A way that is not so optimized, but that works, would be to check if inside the tag “storage” there is the word “value”.

jsonFile("Assignments")(0)("body")("storage").ToString.Contains("value")

This will return a true/false condition.

1 Like

WE can check within the nested structures for particular property names using different Options.

For a solution Suggestion IT would be helpfully If you can Provide sample data json Reflecting the true and false case

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