我希望将JSON转换为键-值对,并同时将特定的单个值(即"timestamp"
)复制到所有这些对中。
输入JSON:
{
"Timestamp": "2018-05-13T14:57:09",
"first_key": "1023",
"another_key": "1987",
"yet_another_key": "677"
}
预期产出:
[
{
"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"
}
]
到目前为止,我提出的是下面的JOLT规范,它已经为所有不是“Timestamp”的条目生成了键-值对,但是我如何将“Timestamp”的值复制到这些记录中的每一条中呢?
[
{
"operation": "shift",
"spec": {
"Timestamp": "[].Timestamp",
"*": {
"$": "[#2].key",
"@": "[#2].value"
}
}
}
]
上述JOLT规范的输出:
[
{
"Timestamp": "2018-05-13T14:57:09.087"
},
{
"key": "first_key",
"value": "1023"
},
{
"key": "another_key",
"value": "1987"
},
{
"key": "yet_another_key",
"value": "677"
}
]
2条答案
按热度按时间ijnw1ujt1#
质量标准
ddrv8njm2#
您可以在移位转换规范中循环以**
_key
**结尾的属性,例如其中**
"@1,Timestamp"
表示遍历树的一个级别后获取Timestamp
属性的值http://jolt-demo.appspot.com/站点上的演示**是