簡體   English   中英

顛簸變換數組數據

[英]Jolt transformation array data

我想像這樣使用 JOLT 轉換 JSON:

Input: {
    "array": [
       "1","2","3","4"
    ],
    "array2": [
       {  
          "something": "123",
          "something1": "Plane"
       },
       {
          "something3": "567",
          "something4": "Car"
       }
    ]
}

轉換為以下格式,正如您從 output 中看到的那樣,我需要來自 arrays 的數據以適合確切的參數名稱,而不是像第一個那樣為空的或像第二個那樣存在的參數名稱。

Output: {
    "one_array": [
      {
       "code": "1", 
       "description": "", 
      },
      {
       "code": "2", 
       "description": "", 
      },
      {
       "code": "3", 
       "description": "", 
      },
      {
       "code": "4", 
       "description": "", 
      }
], "other_array": [
      {
          "id": "123",
          "type": "Plane"
      }, 
      {
          "id": "567",
          "type": "Car"
      }
]
}

一些澄清非常感謝

您可以使用 2 shift操作和下面的default操作來實現此目的。

[
  {
    "operation": "shift",
    "spec": {
      "array": {
        "*": {
          "@": "one_array[&].id"
        }
      },
      "array2": {
        "*": {
          "*": {
            "@": "tmp_array[&2]"
          }
        }
      }
    }
   },
  {
    "operation": "shift",
    "spec": {
      "one_array": "one_array",
      "tmp_array": {
        "*": {
          "0": "other_array[&1].id",
          "1": "other_array[&1].type"
        }
      }
    }
   },
  {
    "operation": "default",
    "spec": {
      "one_array[]": {
        "*": {
          "description": ""
        }
      }
    }
   }
]

暫無
暫無

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

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