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.