'JSON conversion using JOLT with ARRAY
someone can me help? I'm new to jolt. Can you please tell me how can i trasform the below json message with array based upon the position in to the below output json message using jolt.
My JSON is:
{
"cargas": [
{
"pedidos": [
{
"chavePedido": "003/0125238-P",
"sequencia": [
"1"
]
},
{
"chavePedido": "003/0135001-P",
"sequencia": [
"2"
]
}
],
"transportadora": {
"nome": "TRANSPRIMO TRANSPORT",
"cnpj": "08.689.799/0001-87",
"endereco": "",
"bairro": "",
"cidade": "",
"estado": "",
"cep": "13715000"
},
"motorista": {
"cnpjCpf": "26308191833",
"nome": "ALEXANDRE"
},
"carro": {
"placa": "MZQ4743",
"descricao": "furgão Mercedes-Benz3"
},
"observacao": "informação id Lincros"
}
]
}
How do I formulate my ''jolt''?
output json:
"transportadora": {
"nome": "TRANSPRIMO TRANSPORT",
"cnpj": "08.689.799/0001-87",
"endereco": "",
"bairro": "",
"cidade": "",
"estado": "",
"cep": "13715000"
},
"motorista": {
"cnpjCpf": "26308191833",
"nome": "ALEXANDRE"
},
"carro": {
"placa": "MZQ4743",
"descricao": "furgão Mercedes-Benz3"
}
I need the data of transportadora, motorista and carro, but I don't know how I'm going to get this data.
Thanks.
Solution 1:[1]
The expected result is not a valid JSON value, but if you need wrapped current value with curly braces, then use such a shift transformation
[
{
"operation": "shift",
"spec": {
"cargas": {
"*": {
"transportadora|motorista|carro": "&"
}
}
}
}
]
as walking the indexes of cargas list for the desired objects those are seperated by | characters in order to denote or logical operator.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Barbaros Özhan |

