09-12-2023 11:42 AM
Hello
I am having trouble extracting a nested JSON array that looks like this:
{
"name": "Acme",
"color": "blue",
"animal": "dog",
"employee": [ { "first_name": "Bob", "last_name": "Smith", "age": 32 },
{"first_name": "Joe", "last_name": "Doe", "age": 44 } ] }
And my desired output is something like this:
{
"name": "Acme",
"color": "blue,
"animal": "dog",
"first_name": "Bob",
"last_name": "Smith",
"age": 32
},
{
"name": "Acme",
"color": "blue,
"animal": "dog",
"first_name": "Joe",
"last_name": "Doe",
"age": 44
}
I have tried to use two consecutive mappers but that did not work.
I would appreciate any suggestions and pipeline examples, thank you!
#mapper #json #jsonnested
Solved! Go to Solution.
09-13-2023 05:08 AM
@rpc1235x - Below is a pipeline that demonstrates how to use the JSON Splitter for your example. I'm using the JSON Generator to generate your source records.
Hope this clarifies!
09-12-2023 11:50 AM
@rpc1235x - take a look at the JSON Splitter snap. For your example, you will want to enable the "Include scalar parents" option to retain the name, color, and animal attributes.
09-12-2023 12:54 PM
JSON Splitter snap already set to Include scalar parents.
In the mapper I have Expression: $['wd:employee']['wd:first_name'] and Target path: first_name, but what is happening is that it only outputs the arrays that only contain one (the first one only) nested array in employee. It does not create the desired output of like in the example, two data arrays.
09-13-2023 05:08 AM
@rpc1235x - Below is a pipeline that demonstrates how to use the JSON Splitter for your example. I'm using the JSON Generator to generate your source records.
Hope this clarifies!