How to approach when we have array of data to be distributed as key value paired array
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-30-2020 02:47 PM
Hi,
I am running lot of iterations, but not able to find the solution for below case :
Case :
Input is an array like below :
{ "olditem": [ { "id": "1" }, { "id": "2" }, { "id": "3" }, { "id": "4" }, { "id": "5" } ] }
This need to be mapped to output payload which has array with id keys as below
"{ "batch": [ { "row": "1" }, { "row": "2" }, { "row": "3" }, { "row": "4" }, { "row": "5" } ] }
Note : this elements can be at any hierarchy in the JSON payload. also id counts is dynamic
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-01-2020 12:29 AM
Can Anybody Help on this ?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-01-2020 01:50 AM
Hi @vaidyarm,
I’ve put together a pipeline where I simulate your case. In it I propose two solutions. Assuming that the $olditem array is anywhere in the hierarchy of the input document:
- If you put
jsonPath($,"$..olditem")[0].map(x=>{"row":x.id})
in an Expression in a Mapper, and assign it to $batch Target Path, you should get the output you described. - The second solution has 2 Mapper Snaps. In the first one, I extract $olditem from anywhere in the hierarchy and assign it to $batch. In the second Mapper, i designate
$batch[*]
as Mapping Root, and I proceed to remap the array elements.
Here’s the pipeline:
Array_key_value_pair_2020_07_01.slp (9.0 KB)
BR,
Dimitri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-04-2020 11:27 AM
Thanks a Lot !!,
The root element approach greatly resolved most of the deep JSON Section problems.
one of the situations where I had multiple such cases,
Ex: hierarchy as main >> subsection >> item >> item details
started mapping the deepest section first using root path in mapper and finally the outermost part. it distributed the arrays as required
