【发布时间】:2022-11-02 04:22:55
【问题描述】:
我正在尝试使用 Jolt 转换来转换 JSON,在此处寻找一些输入。 我正在尝试将部分项目放入一个数组中。我的目标是获得一个包含部分项目的数组。
这是我的输入和预期输出:
输入:
{
"item": [
{
"ac": "i",
"id": "c5b9e16076fe4faaaace5c7d0cbe0d9b",
"foo": {
"id": "c5b9e16076fe4faaaace5c7d0cbe0d9b",
"nn": "de38c8a2e6a844d1a9dd7a573eedee15"
},
"item": [
{
"ac": "y",
"id": "c5b9e16076fe4faaaace5c7d0cbe0d9b",
"foo": {
"id": "c5b9e16076fe4faaaace5c7d0cbe0d9b",
"nn": "b1754500dde646f1af495814fcd2d65e"
}
},
{
"id": "r",
"ac": "ac",
"foo": {
"id": "c5b9e16076fe4faaaace5c7d0cbe0d9b",
"nn": "bfb5550a6d754892b313ab9dd8604725"
}
}
]
}
]
}
预期产出:
[
{
"ac": "y",
"foo": {
"nn": [
"b1754500dde646f1af495814fcd2d65e"
]
}
},
{
"ac": "i",
"foo": {
"nn": "de38c8a2e6a844d1a9dd7a573eedee15"
}
},
{
"ac": "r",
"foo": {
"nn": "bfb5550a6d754892b313ab9dd8604725"
}
}
]
我的规格:
[
{
"operation": "shift",
"spec": {
"item": {
"*": {
"item": {
"*": {
"item": {
"*": {
"ac": "[&1].ac",
"foo": {
"nn": "[&2].foo.&"
}
}
},
"ac": "[&1].ac",
"foo": {
"nn": "[&2].foo.&"
}
}
},
"ac": "[&1].ac",
"foo": {
"nn": "[&2].foo.&"
}
}
}
}
}
]
结果出乎我的意料,我得到了:我的输出:
[ {
"ac" : [ "y", "i" ],
"foo" : {
"nn" : [ "b1754500dde646f1af495814fcd2d65e", "de38c8a2e6a844d1a9dd7a573eedee15" ]
}
}, {
"ac" : "ac",
"foo" : {
"nn" : "bfb5550a6d754892b313ab9dd8604725"
}
} ]
ac 列表和 KK 列表不是 item 的每个属性一起在一个 item 列表中
你能告诉我怎么做吗?
【问题讨论】: