โ10-21-2019 05:48 AM
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โ}
}
โ10-21-2019 10:33 AM
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)
โ10-21-2019 11:13 AM
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)