我从昨天开始一直在研究 Jolt 转换,但无法找到实现以下输出的解决方案。
我想在"记录"列表的每个地图(字典(中插入"年","月","日"。
输入
[{"root":
{"body":
{"year":2019,
"month":8,
"day":9,
"records":[
{"user":"a",
"item":"x",
"price":300,
"count":1},
{"user":"b",
"item":"y",
"price":100,
"count":3}]
}
}
}]
期望的输出
[{"user":"a",
"item":"x",
"price":300,
"count":1,
"year":2019,
"month":8,
"day":9},
{"user":"b",
"item":"y",
"price":100,
"count":3,
"year":2019,
"month":8,
"day":9}
]
我可以在每个地图的外部插入"年","月","日"的值作为列表,例如{"记录":[[2019,8,9],{map1},{map2}]},但这不是我想要的。
我感谢任何帮助或建议。并提前感谢您。
这应该可以做你想要的:
解决方案(内联说明(:
[
{
"operation": "shift",
"spec": {
"*": {
"root": {
"body": {
"records": {
//match records array
"*": {
//copy object user, item etc. to current position
"@": "[&1]",
//go up two levels and get year and place it in current array position
"@(2,year)": "[&1].year",
"@(2,month)": "[&1].month",
"@(2,day)": "[&1].day"
}
}
}
}
}
}
}
]
输出:
[
{
"user": "a",
"item": "x",
"price": 300,
"count": 1,
"year": 2019,
"month": 8,
"day": 9
},
{
"user": "b",
"item": "y",
"price": 100,
"count": 3,
"year": 2019,
"month": 8,
"day": 9
}
]