如何使用using转换破坏和平平嵌套的JSON数组
发自:
{
"product": [
"test1",
"test2"
],
"Purchase": [
1,
2
],
"Renewal": [
1,
2
]
}至:
[
{
"product": "test1",
"Purchase": 1,
"Renewal": 1
},
{
"product": "test2",
"Purchase": 2,
"Renewal": 2
}
]为了符合sql格式,我想将这个数组json文件压平。
发布于 2022-10-07 13:04:17
您可以使用shift转换规范,例如
[
{
"operation": "shift",
"spec": {
"*": {
"*": {
"@": "[#2].&2"
}
}
}
}
]其中,&2叶将值划分为新的子数组,方法是将值划分到各个级别,以获取它们当前各自的数组名称,而[#2]则重新组织它们以形成对象数组。
站点上的演示 http://jolt-demo.appspot.com/是

编辑:如果输入与下面的输入类似,请按照最后一个注释中的要求
{
"product": [
"test- 1",
"test- 2"
],
"Purchase": [
2,
2
],
"Renewal": 1
}然后你可以考虑使用
[
{
"operation": "shift",
"spec": {
"*r*": {
"*": {
"@": "[#2].&2",
"@(2,Renewal)": "[#2].Renewal"
}
}
}
},
{
"operation": "cardinality",
"spec": {
"*": {
"Re*": "ONE"
}
}
}
]https://stackoverflow.com/questions/73987454
复制相似问题