我正在努力更新我的震动规格以生成正确的输出。我已经进行了第一次尝试,但不幸的是,为了获得良好的结果,我的规范中缺少一些内容。
这是我的json输入
{
"id": 111,
"uuid": "b4915b22-d8c0-47bd-832c-18c0",
"testKey1[xxx]": "identifier_1234",
"testKey2[yyyy]": "identifier_14",
"name": "name1",
"testValue1[xxx]": "10",
"testValue2[yyy]": "12",
"address": "S2271",
"updateTime": "2024-01-18T10:35:00Z"
}
这是我的震动规格
[
{
"operation": "shift",
"spec": {
"uuid": "idBus",
"id": "idTech",
"name": "title",
"address": "location",
"updateTime": "lastUpdated",
"testValue*": "myList&.value",
"testKey*": "myList&.code"
}
},
{
"operation": "shift",
"spec": {
"*": "&",
"myList*": "myListOfFields[]"
}
}
]
实际我有这个输出
{
"idBus" : "b4915b22-d8c0-47bd-832c-18c0",
"idTech" : 111,
"title" : "name1",
"location" : "S2271",
"lastUpdated" : "2024-01-18T10:35:00Z",
"myListOfFields" : [ {
"value" : "identifier_1234"
}, {
"value" : "identifier_14"
}, {
"code" : "10"
}, {
"code" : "12"
} ]
}
我想要的输出是这样的
{
"idBus" : "b4915b22-d8c0-47bd-832c-18c0",
"idTech" : 111,
"title" : "name1",
"location" : "S2271",
"lastUpdated" : "2024-01-18T10:35:00Z",
"myListOfFields" : [
{
"code" : "identifier_1234",
"value"" : "10"
}, {
"code" : "identifier_14",
"value" : "12"
} ]
}
为了达到预期的输出,是否有遗漏的部分? 任何帮助将不胜感激
谢谢。
您可以这样处理问题:
[
{
"operation": "shift",
"spec": {
"uuid": "idBus",
"id": "&Tech",
"name": "title",
"address": "location",
"updateTime": "lastUpdated",
"test*ue*\\[*": "mLOF&(0,2).value",
"test*ey*\\[*": "mLOF&(0,2).code"
}
},
{
"operation": "shift",
"spec": {
"*": "&",
"mLOF*": "myListOfFields[]"
}
}
]
其中的技巧是用
&(0,2)
标识符分隔,以获得 1
表达式中的序数 2
、testValue..[...]
。