I have a JSON like this:
[
{
"id": "28573041|utm_source=vodafone&utm_medium=banner&utm_campaign=smartphones",
"date": "2022-05-03"
},
{
"id": "28573041|utm_campaign=Vodafone_uppers_2022",
"date": "2022-05-03"
}
]
I want to split these ids like:
:
- this is actual id;=
- this is a property name for parameters;=
- this is a property value;I want to parse it and get this result:
{
{
"id" : "28573041",
"date" : "2022-05-03",
"utm_source" : "vodafone",
"utm_medium" : "banner",
"utm_campaign" : "smartphones"
},
{
"id" : "28573041",
"date" : "2022-05-03",
"utm_campaign" : "Vodafone_uppers_2022"
}
}
Parameters can be different after |
and order is not guaranteed, but only possible 5 variants: -
Any ways to do it with JOLT or other NiFi tools?
Other solution in this case.
[
{
"operation": "modify-overwrite-beta",
"spec": {
"*": {
"aux": "=split(\\|,@(1,id))",
"id": "=firstElement(@(1,aux))",
"newInfo": "=lastElement(@(1,aux))",
"auxFinal": "=split(&,@(1,newInfo))"
}
}
},
{
"operation": "shift",
"spec": {
"*": {
"id": "[#2].&",
"date": "[#2].&",
"auxFinal": {
"*": {
"@": "[#4].fields[].field"
}
}
}
}
},
{
"operation": "modify-overwrite-beta",
"spec": {
"*": {
"fields": {
"*": {
"aux": "=split(=,@(1,field))",
"key": "=firstElement(@(1,aux))",
"value": "=lastElement(@(1,aux))"
}
}
}
}
},
{
"operation": "shift",
"spec": {
"*": {
"id": "[#2].&",
"date": "[#2].&",
"fields": {
"*": {
"value": "[#4].@(1,key)"
}
}
}
}
}
]