简体   繁体   中英

JOLT Transformation - Nested Json Object

I have a nested JSON object like this:

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

which I would like to transform to:

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

How do I achieve this using JOLT? Appreciate your inputs.

You can use the following specs

[
  //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)"
        }
      }
    }
  }
]

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM