I need to transform multiple keys and their values to new JSON
source JSON
{
"attributes": [
{
"key": "network",
"value": {
"stringValue": "4G"
}
},
{
"key": "device_id",
"value": {
"stringValue": "1234567890"
}
}
]
}
Expected output:
{
"network": "4G",
"device_id":"1234567890"
}
Thanks in advance
I need to transform multiple keys and their values to new JSON
source JSON
{
"attributes": [
{
"key": "network",
"value": {
"stringValue": "4G"
}
},
{
"key": "device_id",
"value": {
"stringValue": "1234567890"
}
}
]
}
Expected output:
{
"network": "4G",
"device_id":"1234567890"
}
Thanks in advance
Share Improve this question edited Jan 30 at 8:39 Barbaros Özhan 65.4k11 gold badges36 silver badges61 bronze badges asked Jan 30 at 8:31 Будён Михайлович СемённыйБудён Михайлович Семённый 312 bronze badges 01 Answer
Reset to default 2You can use a shift transformation that matches those keys :
[
{
"operation": "shift",
"spec": {
"*": {//stands for the level of the "attributes" array
"*": {// for the indexes of the array
"@value.stringValue": "@key"
}
}
}
}
]
the demo on the site Jolt Transform Demo Using v0.1.1 is :
Edit(based on the comment) : If only needed to bring the device_id
, they you could use a conditional logic by the following spec :
[
{
"operation": "shift",
"spec": {
"*": {
"*": {
"key": {
"device_id": {
"@2,value.stringValue": "&1"
}
}
}
}
}
}
]