โ02-07-2018 01:21 AM
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,
Splitting this at $โฆIDOC and I get below as output,
I need the output as,
The root element will be dynamic and need to capture that and should be available after the split.
Any help will be appreciated.
Solved! Go to Solution.
โ02-08-2018 04:46 AM
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!
โ02-07-2018 02:32 AM
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.
โ02-07-2018 05:22 AM
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?
โ02-07-2018 05:37 AM
Ah i missed the dynamic part, apologies my advice is useless then.
โ02-07-2018 10:49 AM
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.