簡體   English   中英

JOLT 轉換 - 嵌套的 Json 對象

[英]JOLT Transformation - Nested Json Object

我有一個這樣的嵌套 JSON 對象:

{
   "0":{
      "testone":72,
      "testtwo":1
   },
   "1":{
      "testone":72,
      "testtwo":1
   },
   "2":{
      "testone":72,
      "testtwo":1
   }
}

我想轉換為:

[
   {
      "one":72,
      "two":1
   },
   {
      "one":72,
      "two":1
   },
   {
      "one":72,
      "two":1
   }
]

我如何使用 JOLT 實現這一目標? 感謝您的投入。

您可以使用以下規格

[
  //exchange key and values  
  {
    "operation": "shift",
    "spec": {
      "*": {
        "*": {
          "$": "[&2].@(0)"
        }
      }
    }
  },
  //split the values by the prefix "test"
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "*": {
        "*": "=split('test',@(1,&))"
      }
    }
  },
  //get rid of the prefixes "test" 
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "*": {
        "*": "=join('',@(1,&))"
      }
    }
  },
  //re-exchange key and values  
  {
    "operation": "shift",
    "spec": {
      "*": {
        "*": {
          "$": "[&2].@(0)"
        }
      }
    }
  }
]

在此處輸入圖片說明

暫無
暫無

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

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