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)