我试图通过将列表值从输入JSON带到主对象来将JSON转换为JSON,但我发现语法很混乱。
输入JSON:
[
{
"Request": {
"Id": "id1",
"name": "5-221734537593",
"CreatedBy": "abc",
"Updated": "02/28/2023 19:48:41",
"UpdatedBy": "xyz",
"ListOfNotes": {
"Notes": [
{
"sent": "Y",
"Id": "id2",
"Created": "02/28/2023 19:46:00",
"CreatedBy": "lmn",
"Updated": "02/28/2023 19:46:06",
"UpdatedBy": "efg"
},
{
"sent": "Y",
"Id": "id2",
"Created": "02/28/2023 19:46:00",
"CreatedBy": "lmn",
"Updated": "02/28/2023 19:46:06",
"UpdatedBy": "efg"
}
]
},
"ListOfActions": {
"Actions": [
{
"actId": "123",
"actionPerformed": "y",
"actionBy": "abc"
},
{
"actId": "234",
"actionPerformed": "y",
"actionBy": "xyz"
}
]
}
}
}
]
预期产出:
[
{
"Id": "id1",
"name": "5-221734537593",
"CreatedBy": "abc",
"Updated": "02/28/2023 19:48:41",
"UpdatedBy": "xyz"
},
{
"Notes": [
{
"sent": "Y",
"Id": "id2",
"Created": "02/28/2023 19:46:00",
"CreatedBy": "lmn",
"Updated": "02/28/2023 19:46:06",
"UpdatedBy": "efg"
},
{
"sent": "Y",
"Id": "id2",
"Created": "02/28/2023 19:46:00",
"CreatedBy": "lmn",
"Updated": "02/28/2023 19:46:06",
"UpdatedBy": "efg"
}
]
},
{
"Actions": [
{
"actId": "123",
"actionPerformed": "y",
"actionBy": "abc"
},
{
"actId": "234",
"actionPerformed": "y",
"actionBy": "xyz"
}
]
}
]
尝试的规范:
[
{
"operation": "shift",
"spec": {
"*": {
"Request": {
"Id": "[#].&",
"name": "[#].&",
"CreatedBy": "[#].&",
"Updated": "[#].&",
"UpdatedBy": "[#].&"
}
}
}
}
]
我当前得到的输出缺少Notes和Actions字段,我不确定如何正确地转换它们。
[
{
"Id": "id1",
"name": "5-221734537593",
"CreatedBy": "abc",
"Updated": "02/28/2023 19:48:41",
"UpdatedBy": "xyz"
}
]
2条答案
按热度按时间jdgnovmf1#
您可以使用以下shift转换规范
nkkqxpd92#
如果输入JSON的顺序是不同的,下面的JOLT规范可以更精确。