0

需要根据元素值input.json进行变换

{
  "Result": {
    "owner": {
      "name": "test  user"
    },
    "Components": [
      {
        "id": "123-456-789"
      }
    ],
    "123-456-789": {
      "temp": {
        "emip": "abc",
        "teto": "123"
      }
    }
  }
}

转换json

[
  {
    "operation": "shift",
    "spec": {
      "Result": {
        "Components": {
          "*": {
            "id": "compId"
          }
        },
        "compId": {
          "@": "component"
        }
      }
    }
  },
  {
    "operation": "default",
    "spec": {
      "compId": null
    }
  }
]

预计输出为

 "123-456-789": {
      "temp": {
        "emip": "abc",
        "teto": "123"
      }
    }

但结果答案如下,当我用 123-456-789 对值进行硬编码时,我得到了该值,但我需要动态获取该值。

{
  "compId" : "123-456-789"
}
4

1 回答 1

0

规格

[
  {
    "operation": "shift",
    "spec": {
      "Result": {
        "Components": {
          "*": { // components array index
            "id": {
              "*": { // match any value of id
                // go back up the tree 5 levels, and then 
                //  lookup a key based on the value of the "id"
                //  and write that to the output at at that same 
                //  key
                "@(4,&)": "&1"
              }
            }
          }
        }
      }
    }
  }
]
于 2018-02-13T14:17:58.030 回答