JSON Node to a Key/Value

Hi,
I have a JSON table coming in like this:
{
“344-2-3-pt_2_fsfsf1_GDT” : {
“id” : “fsfsf1”,
“type” : “single”,
“groupid” : “2”,
“islast” : “0”,
“max_score” : “”,
“context” : “GDT”
},
“344-2-3-pt_2_fsfsf2_GDT” : {
“id” : “fsfsf2”,
“type” : “single”,
“groupid” : “2”,
“islast” : “0”,
“max_score” : “”,
“context” : “GDT”
}
}

I would like to convert the parent node to a key value pair, like this for example OR is there a way I can just get the value of that parent node?
[
{
“ref” : “344-2-3-pt_2_fsfsf1_GDT”,
“id” : “fsfsf1”,
“type” : “single”,
“groupid” : “2”,
“islast” : “0”,
“max_score” : “”,
“context” : “GDT”
},
{
“ref” : “344-2-3-pt_2_fsfsf2_GDT”,
“id” : “fsfsf2”,
“type” : “single”,
“groupid” : “2”,
“islast” : “0”,
“max_score” : “”,
“context” : “GDT”
}
]

Thanks a lot!

1 Like

Tried using JSON Path, but did not work well

Hi @rumanac , in the future, when pasting such data, please use the Preformatted text option:
image

That way, the quotes would not be converted to opening and closing quotes, and we would not have to spend time fixing the input data :slight_smile:

I did both alternatives that you were looking for “convert the parent node to a key value pair” or “just get the value of that parent node”, so you can use either.

Both are included in the same workflow, which looks like this:

Input data:
image

Here are the values of the parent nodes:
image

And here is the other alternative where the parent node is converted as value to the ref variable, and is in an array as per your screenshot:
image

FYI, you can’t have an empty/unnamed array, so I added “root” as a name.

Here’s the workflow: JSON Node to a Key-Value.knwf (21.8 KB)

5 Likes

Thank you so much Bruno! This was highly helpful!
Rumana

2 Likes

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