I have this JSON
[
{
"nomclient": "diattara",
"prix": 15,
"ville": "Paris",
"typeproduit": "boisson",
"produit": [
"COCA",
"RedBull"
]
},
{
"nomclient": "kamel",
"prix": 250,
"ville": "Marseille",
"typeproduit": "beurre",
"produit": [
"auchan"
]
}
]
I want to apply a jolt Transforme in NIFI to get a JSON like this:
[
{
"nomclient": "diattara",
"prix": 15,
"ville": "Paris"
},
{
"nomclient": "kamel",
"prix": 15,
"ville": "Paris"
}
]
I tried this spec but the result was not good
[
{
"operation": "shift",
"spec": {
"*": {
"ville": "ville",
"prix": "prix"
}
}
}
]
could you help me please
If you want to keep the values of the first entry's prix
and ville
values for all the nomclient
entries, you can use the following spec in JoltTransformJSON:
[
{
"operation": "shift",
"spec": {
"*": {
"@(1,[0].prix)": "[&1].prix",
"@(1,[0].ville)": "[&1].ville",
"nomclient": "[&1].&"
}
}
}
]
If you want to just keep the 3 fields from each entry you can use the following spec:
[
{
"operation": "shift",
"spec": {
"*": {
"prix": "[&1].&",
"ville": "[&1].&",
"nomclient": "[&1].&"
}
}
}
]