I have incoming data like the below mentioned:
Input :
{
"results": {
"columns": [
[
"id",
"name",
"type"
],
[
"id",
"name",
"type"
],
[
"id",
"name",
"type"
]
],
"rows": [
[
"D01",
"vm01",
"vms"
],
[
"D02",
"vm02",
"vms"
],
[
"D03",
"vm03",
"vms"
]
]
}
}
The columns are the keys and rows are the values and are expected as key-value pairs
Expected output :
[
{
"id": "D01",
"name": "vm01",
"type": "vms"
},
{
"id": "D02",
"name": "vm02",
"type": "vms"
},
{
"id": "D03",
"name": "vm03",
"type": "vms"
}
]
3
Answers
You can use the following shift transformation spec
Answer with previews
jolt
tag.You can use the following JOLT spec:
How does it work?
Just go to the
rows
items level and get all values with*
use the following code as the place of the keys[&1]
: Index of therows
items (array ofrows
).0, 1, 2
[&]
: Index of therows
items values (arrays ofrows
array).0, 1, 2
@(3,columns)
: Value ofcolumns
.[[], [], []]
@(3,columns[&1])
: Values ofcolumns
items.[], [], []
@(3,columns[&1][&])
: Values ofcolumns
items field.id, name, type
(Answering the question using its original
python
tag…)If you can get a sequence of pairs like
[("id", "D01"), ("name", "vm01"), ("type", "vms")]
, you can create the desireddict
value:You can get such lists by mapping
zip
over each corresponding pair of columns and rows.