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

JSON Splitter removing the data

krupalibshah
Contributor

I am using JSON splitter to split the input document into smaller documents. However the splitter will remove the element on which we are performing the split functionality. I need some work around to either retain it or to be able to add it back after the split.

See example below,

image

Splitting this at $โ€ฆIDOC and I get below as output,

image

I need the output as,

image

The root element will be dynamic and need to capture that and should be available after the split.

Any help will be appreciated.

1 ACCEPTED SOLUTION

My problem was to be able to add the parent element dynamically, worked by using JSON generator,

{
  $root:
  {
        "IDOC" :$payload
    }
}

Got the value of โ€œrootโ€ from expression library ๐Ÿ™‚

Thanks for the help!

View solution in original post

6 REPLIES 6

nisars
New Contributor III

Hi krupalibshah,

You can add fields you need in the โ€˜include pathsโ€™ section of the json splitter. I either pass all the fields i need if there are a couple. or i copy the data before the json splitter, include the primary key in the json splitter and use it to join the datasets again using a left join.

Do we have any leads who has done this kind of thing using expression lib or language? As we want to make this functionality general we are looking into the option to do it.

@tstack can you help me here?

nisars
New Contributor III

Ah i missed the dynamic part, apologies my advice is useless then.

tstack
Former Employee

Unfortunately, the JSON Splitter snap does not expose the fully resolved path to the element being output. Iโ€™ve filed a feature request to add this functionality. In the meantime, youโ€™ll need to use a Mapper with an expression to add the parent key name into the child object. For instance, the following expression will transform the input document to add a โ€œparentโ€ property to all objects with the name of the parent:

$.mapValues((v, k) => v instanceof Object ? v.extend({parent: k}) : v)

Since youโ€™re transforming the whole input document, youโ€™ll want to use $ as the output document.

Then, in the JSON Splitter, you can use the โ€˜Include scalar parentsโ€™ option to have the โ€˜parentโ€™ property added into the output documents.