I want to transform a JSON into key-value pairs and simultaneously copy a specific single value, i.e. the "timestamp"
, to all these pairs.
Input JSON:
{
"Timestamp": "2018-05-13T14:57:09",
"first_key": "1023",
"another_key": "1987",
"yet_another_key": "677"
}
Expected output:
[
{
"Timestamp": "2018-05-13T14:57:09.087",
"key": "first_key",
"value": "1023"
},
{
"Timestamp": "2018-05-13T14:57:09.087",
"key": "another_key",
"value": "1987"
},
{
"Timestamp": "2018-05-13T14:57:09.087",
"key": "yet_another_key",
"value": "677"
}
]
What I came up with so far is the following JOLT specification. It already generates the key-value pairs for all entries that are not "Timestamp", but how can I copy the value of "Timestamp" into each of these records?
[
{
"operation": "shift",
"spec": {
"Timestamp": "[].Timestamp",
"*": {
"$": "[#2].key",
"@": "[#2].value"
}
}
}
]
Output of the above JOLT specification:
[
{
"Timestamp": "2018-05-13T14:57:09.087"
},
{
"key": "first_key",
"value": "1023"
},
{
"key": "another_key",
"value": "1987"
},
{
"key": "yet_another_key",
"value": "677"
}
]