摇动,沿数组复制值

时间:2018-10-25 19:37:09

标签: json jolt

我想通过JOLT通过以下方式转换JSON:

输入json文件

{
  "Document_No": "ANG4",
  "LineNo10": {
    "Type": 1,
    "Customer_No_": "1"
  },
  "LineNo11": {
    "Type": 2,
    "Customer_No_": "2"
  },
  "LineNo12": {
    "Type": 3,
    "Customer_No_": "3"
  }
}

所需的json文件输出

  [ 
    {
      "Document_No":"ANG4"  
      "Type" : 1,
      "Customer_No_" : "1",
      "Line_No" : "10"
    }, 
    {
      "Document_No":"ANG4"
      "Type" : 2,
      "Customer_No_" : "2",
      "Line_No" : "11"
    }, 
    {
      "Document_No":"ANG4"
      "Type" : 3,
      "Customer_No_" : "3",
      "Line_No" : "12"
    } 
    ]

我并不缺少很多,但是我不知道为了获得期望的输出而添加了哪些转换

我的Jolt规格低于

[
  {
    "operation": "shift",
    "spec": {
      "LineNo*": {
        "@": "&",
        "$": "&.Line_No"
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "*": {
        "@": "[]"
      }
    }
  }
]

我的输出json文件:

[ {
  "Type" : 1,
  "Customer_No_" : "1",
  "Line_No" : "LineNo10"
}, {
  "Type" : 2,
  "Customer_No_" : "2",
  "Line_No" : "LineNo11"
}, {
  "Type" : 3,
  "Customer_No_" : "3",
  "Line_No" : "LineNo12"
} ]

有人可以帮我吗?

1 个答案:

答案 0 :(得分:0)

规格

[
  {
    "operation": "shift",
    "spec": {
      "LineNo*": {
        // copy Document_No down into the "LineNo" maps
        "@(1,Document_No)": "&1.Document_No",
        "$": "&1.Line_No",
        "*": "&1.&"
      }
    }
  },
  {
    // accumulate all the "built" LineNo's into an array
    "operation": "shift",
    "spec": {
      "*": {
        "@": "[]"
      }
    }
  }
]