簡體   English   中英

顛簸列表轉換

[英]Jolt List Transformation

我正在嘗試使用 jolt 轉換 JSON 而不添加新項目以及從鍵值中刪除空格。 另外,我想知道如何將 map 加入當前列表。

輸入

[
  {
    "id": "9164339966213408050",
    "actualEndDate": "2022-08-15T14:47:09+03:00",
    "extendedChars": [
      {
        "Total BYOP Tier": {
          "values": [
            {
              "value": "60"
            }
          ],
          "name": "Total BYOP Tier",
          "isMultiple": false,
          "tomsId": "9162933742365468326"
        }
      }
    ],
    "chars": {
      "Total BYOP Tier": "60"
    }
  },
  {
    "id": "9164339966213408051",
    "actualEndDate": "2022-08-15T14:47:09+03:00",
    "extendedChars": [
      {
        "Total BYOP Tier": {
          "values": [
            {
              "value": "60"
            }
          ],
          "name": "Total BYOP Tier",
          "isMultiple": false,
          "tomsId": "9162933742365468325"
        }
      }
    ],
    "chars": {
      "Total BYOP Tier": "60"
    }
  }
]

預期 output

[
  {
    "id": "9164339966213408050",
    "actualEndDate": "2022-08-15T14:47:09+03:00",
    "extendedChars": [
      {
        "values": [
          {
            "value": "60"
          }
        ],
        "name": "Total BYOP Tier",
        "isMultiple": false,
        "tomsId": "9162933742365468326",
        "TotalBYOPTier": {
          "values": [
            {
              "value": "60"
            }
          ],
          "name": "Total BYOP Tier",
          "isMultiple": false,
          "tomsId": "9162933742365468326"
        }
      }
    ],
    "chars": {
      "TotalBYOPTier": "60"
    }
  },
  {
    "id": "9164339966213408051",
    "actualEndDate": "2022-08-15T14:47:09+03:00",
    "extendedChars": [
      {
        "values": [
          {
            "value": "60"
          }
        ],
        "name": "Total BYOP Tier",
        "isMultiple": false,
        "tomsId": "9162933742365468325",
        "TotalBYOPTier": {
          "values": [
            {
              "value": "60"
            }
          ],
          "name": "Total BYOP Tier",
          "isMultiple": false,
          "tomsId": "9162933742365468325"
        }
      }
    ],
    "chars": {
      "TotalBYOPTier": "60"
    }
  }
]

規格嘗試:

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "@": "CustomerProductArray"
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "CustomerProductArray": {
        "*": {
          "extendedChars": {
            "*": {
              "* * *": "CustomerProductArray.&(0,1)&(0,2)&(0,3)",
              "*": {
                "name": "CustomerProductArray[].extendedChars[]..name",
                "isMultiple": "CustomerProductArray[].extendedChars[].isMultiple",
                "tomsId": "CustomerProductArray[].extendedChars[].tomsId",
                "values": "CustomerProductArray[].extendedChars[].values"
              }
            }
          },
          "chars": {
            "* * *": "CustomerProductArray[].chars.&(0,1)&(0,2)&(0,3)"
          }
        }
      }
    }
  }
]

使用以下規范,因為您要復制Total BYOP Tier組的內容,嵌套在 object 內部和外部

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "*": "&1.&",
        "extendedChars": {
          "*": {
            "Total BYOP Tier": {
              "*": {
                "@": "&5.&4[&3].&" // &5 : (going up the tree five levels) replicates the index of the outermost array, &4[&3] : stands for "extendedChars"(&4) along strolling through with its indexes([&3])
              },
              "@": "&4.&3[&2].&1"
            }
          }
        }
      }
    }
  },
  {
   // get rid of object labels
    "operation": "shift",
    "spec": {
      "*": ""
    }
  }
]

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

在此處輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM