2

我正在尝试将一些额外的字段添加到输入 json 中不存在的列表中。如果它是一个对象,我可以添加字段,但我无法将字段添加到数组中。请有人帮我写一个规范。

input JOSN is:

[
    {
        "List": [
            {
                "ITEM_NO": "abcd"
            }
        ]
    }
]

写了一个规范文件

SPEC File is:

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "List": {
          "0": {
            "ITEM_NO": "risk[0].one"
          }
        }
      }
    }
  },
  {
    "operation": "default",
    "spec": {
      "risk": [{
        "two": "efgh",
        "three":"ijkl"
      }]
    }
  }
]

但是输出并不像预期的那样

expeted output is:

{
  "risk" : [ {
    "one" : "abcd",
    "two":"efgh",
    "three":"ijkl"
  } ]
}

如何添加额外的字段?

4

1 回答 1

4

规格

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "List": {
          "0": {
            "ITEM_NO": "risk[0].one"
          }
        }
      }
    }
  },
  {
    "operation": "default",
    "spec": {
      "risk[]": {
        "0": {
          "two": "efgh",
          "three": "ijkl"
        }
      }
    }
  }
]

产生你想要的输出,但不确定你想要做什么。

于 2016-10-05T20:11:36.593 回答