json 多个数组的JOLT变换问题

smdncfj3  于 2023-10-21  发布在  其他
关注(0)|答案(1)|浏览(116)

我有下面的Jolt输入规范。在这里我需要一个不同格式的输出

{
  "EBody": {
    "ServiceDetails": {
      "LineDetail": {
        "LineNumber": [
          "0",
          1
        ],
        "Description": [
          "detail 1",
          "A205330410780"
        ],
        "Amount": [
          "1",
          "2.00"
        ],
        "Unit price": [
          "45.00",
          "2,181.66"
        ],
        "VAT Rate": "0.00%",
        "SurchargeDiscount": {
          "Type": "SC",
          "Percentage": "20.00%",
          "Amount": "872.66"
        },
        "Total Price": "3,490.66"
      }
    }
  }
}

预期输出为:

{
  "EBody": {
    "ServiceDetails": {
      "LinesDetail": [
        {
          "LineNumber": "0",
          "Quantity": "1",
          "Unit Price": "45.00"
        },
        {
          "LineNumber": 1,
          "VAT Rate": "0.00%",
          "Quantity": "2.00",
          "Unit Price": "2,181.66",
          "SurchargeDiscount": {
            "Type": "SC",
            "Percentage": "20.00%",
            "Amount": "872.66"
          }
        }
      ]
    }
  }
}

请帮我看看这个震动的规格。我已经尝试了一些规格,这是不给准确的结果

iih3973s

iih3973s1#

您可以使用以下shift转换规范:

[
  {
    "operation": "shift",
    "spec": {
      "*": { // the level of "EBody"
        "*": { // the level of "ServiceDetails"
          "*D*": { // the level of "LineDetail"
            "LineNumber|Unit price": {
              "*": {
                "@": "&5.&4.&(3,1)sD&(3,2)[&1].&2"
                        // ^here add "s" between "Line" and "Detail"
              }
            },
            "Amount": { // rename Amount to Quantity
              "*": {
                "@": "&5.&4.&(3,1)sD&(3,2)[&1].Quantity"
              }
            },
            "VAT Rate|SurchargeDiscount": "&3.&2.&(1,1)sD&(1,2)[1].&"
          }
        }
      }
    }
  }
]

网站http://jolt-demo.appspot.com/上的***演示***是:

相关问题