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

编辑由于您的评论):不幸的是,没有直接的重命名方法,但可以通过单独编写每个方法来提供解决方法使用下面的键值对

[
  //rename innermost key names
  {
    "operation": "shift",
    "spec": {
      "*": {
        "testone": "&1.one",
        "testtwo": "&1.two"
      }
    }
  },
  //get rid of the object keys
  {
    "operation": "shift",
    "spec": {
      "*": ""
    }
  }
]