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

Mapping requirement

ruchitvijay
New Contributor

I have the following :-
[{
โ€œkeyโ€:[
โ€œnameโ€,
โ€œorganizationโ€,
โ€œcityโ€,
โ€œstateโ€
],
โ€œvalueโ€:[
โ€œabcโ€,
โ€œxyzโ€,
โ€œpuneโ€,
โ€œmaharashtraโ€
]},
{
โ€œkeyโ€:[
โ€œnameโ€,
โ€œorganizationโ€,
โ€œcityโ€,
โ€œstateโ€
],
โ€œvalueโ€:[
โ€œcdeโ€,
โ€œpqrโ€,
โ€œmumbaiโ€,
โ€œmaharashtraโ€
]},
{
โ€œkeyโ€:[
โ€œnameโ€
โ€œcityโ€
โ€œcountryโ€
],
โ€œvalueโ€:[
โ€œdefโ€
โ€œnashikโ€
โ€œindiaโ€
]
}]

how do i convert this into key:value set to write this into csv
Requirement-
{
โ€œnameโ€:{โ€œabcโ€, โ€œcdeโ€, โ€œdefโ€},
โ€œorganizationโ€:{โ€œxyzโ€, โ€œpqrโ€, โ€œnullโ€},
โ€œcityโ€:{โ€œpuneโ€, โ€œmumbaiโ€, โ€œnashikโ€},
country:{โ€œnullโ€, โ€œnullโ€, โ€œindiaโ€}
}

2 REPLIES 2

cjhoward18
Employee
Employee

@ruchitvijay

Is this:

{
โ€œnameโ€:{โ€œabcโ€, โ€œcdeโ€, โ€œdefโ€},
โ€œorganizationโ€:{โ€œxyzโ€, โ€œpqrโ€, โ€œnullโ€},
โ€œcityโ€:{โ€œpuneโ€, โ€œmumbaiโ€, โ€œnashikโ€},
country:{โ€œnullโ€, โ€œnullโ€, โ€œindiaโ€}
}

really your desired data? These objects are invalid since there is not key/value pair. Instead it seems those should be lists like this:

{
โ€œnameโ€:[โ€œabcโ€, โ€œcdeโ€, โ€œdefโ€],
โ€œorganizationโ€:[โ€œxyzโ€, โ€œpqrโ€],
โ€œcityโ€:[โ€œpuneโ€, โ€œmumbaiโ€, โ€œnashikโ€],
country:[โ€œindiaโ€]
}

assuming that you are okay with lists, Iโ€™ve attached an example pipeline with a json generator mocking your given data, and a mapper that produces the results given above.

Basic idea to the approach taken was to zip the key/value pair together, then to reduce the array of pairs into the desired document with a simple ternary operator to see if a concat operation was needed or this was the first time this key was seen then insert a new array.

CommunityExpression_2019_10_21.slp (4.3 KB)

cjhoward18
Employee
Employee

@ruchitvijay

The pipeline above did not preserve the columns(null values). Seeing that you commented about converting this into a CSV, here is a pipeline that does just that. This preserves the columns (null values) as well and can be fed into a CSV formatter (split and then fed in).

CommunityExpression_2019_10_21 (CSV nulls preserved).slp (6.6 KB)