cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Retrieve a JSON Nested objects as individual lines

rpc1235x
New Contributor

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

1 ACCEPTED SOLUTION

koryknick
Employee
Employee

@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.

koryknick_0-1694606787441.png

koryknick_1-1694606805755.png

koryknick_2-1694606831580.png

koryknick_4-1694606912845.png

Hope this clarifies!

 

 

 

View solution in original post

3 REPLIES 3

koryknick
Employee
Employee

@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.

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.

koryknick
Employee
Employee

@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.

koryknick_0-1694606787441.png

koryknick_1-1694606805755.png

koryknick_2-1694606831580.png

koryknick_4-1694606912845.png

Hope this clarifies!