【发布时间】:2021-02-22 18:02:56
【问题描述】:
我正在努力获得所需的输出。谁能帮我找到正确的解决方案。
我尝试了不同的规格并注意到有效。在相应数组下添加父 ID 时遇到问题。
请在这里帮忙。
输入 JSON:
{
"device": {
"id": "336 A6",
"shelves": [
{
"shelfID": "1",
"slots": [
{
"slotID": "1",
"cards": {
"cardID": "1",
"subSlots": [
{
"slotID": "mda-1",
"cards": {
"cardID": "1/1",
"ports": [
{
"portID": "1/1/1",
"adminStatus": "up"
},
{
"portID": "1/1/2",
"adminStatus": "up"
}
]
}
},
{
"slotID": "mda-2",
"cards": {
"cardID": "2/1",
"ports": [
{
"portID": "2/1/1",
"adminStatus": "up"
},
{
"portID": "2/1/2",
"adminStatus": "up"
}
]
}
}
]
}
},
{
"slotID": "11",
"cards": {
"cardID": "11",
"ports": [
{
"portID": "11/1/1",
"adminStatus": "up"
},
{
"portID": "11/1/2",
"adminStatus": "up"
}
]
}
}
]
},
{
"shelfID": "esat-1",
"ports": [
{
"portID": "esat-1/1/1",
"adminStatus": "down"
},
{
"portID": "esat-1/1/2",
"adminStatus": "up"
}
]
}
]
}
}
以下是我尝试过的 JOLT 规范
[
{
"operation": "shift",
"spec": {
"device": {
"shelves": {
"*": {
"ports": {
"*": "physicalResource.ports[&2]",
"@(1,shelfID)": "physicalResource.ports[&2].parentId"
},
"slots": {
"*": {
"cards": {
"ports": {
"*": "physicalResource.ports[&5]",
"@(1,cardID)": "physicalResource.ports[&5].parentId"
},
"subSlots": {
"*": {
"cards": {
"ports": {
"*": "physicalResource.ports[&8]",
"@(1,cardID)": "physicalResource.ports[&8].parentId"
}
}
}
}
}
}
}
}
}
}
}
}
]
预期输出:
{
"physicalResource": {
"ports": [
{
"id": "1/1/1",
"parentId": "1/1",
"state": "up"
},
{
"id": "1/1/2",
"parentId": "1/1",
"state": "up"
},
{
"id": "2/1/1",
"parentId": "2/1",
"state": "up"
},
{
"id": "2/1/2",
"parentId": "2/1",
"state": "up"
},
{
"id": "11/1/1",
"parentId": "11/1",
"state": "up"
},
{
"id": "11/1/2",
"parentId": "11/1",
"state": "up"
},
{
"id": "11/1/1",
"parentId": "11/1",
"state": "up"
},
{
"id": "11/1/2",
"parentId": "11/1",
"state": "up"
},
{
"id": "esat-1/1/1",
"parentSubCardId": "esat-1",
"state": "up"
},
{
"id": "esat-1/1/2",
"parentSubCardId": "esat-1",
"state": "up"
}
]
}
}
谢谢。
【问题讨论】:
-
有人可以帮我解决这个问题吗?
-
您可以在他们的 GitHub 上提交新问题:github.com/bazaarvoice/jolt。
标签: jolt