简体   繁体   English

如何在 JOLT 中获取键的列值

[英]How to get column value of key in JOLT

I'm looking for breaking following nested JSON file and transform it into a SQL prepared format.我正在寻找打破嵌套的 JSON 文件并将其转换为 SQL 准备好的格式。

Input JSON file:输入 JSON 文件:

{
  "Product1": {
    "Purchase": 31
  },
  "Product2": {
    "Purchase": 6213,
    "Cancel": 1988,
    "Change": 3702,
    "Renewal": 5934
  }
}

Desired output:所需的 output:

[
  {
    "product": "Product1",
    "Purchase": 31
  },
  {
    "product": "Product2",
    "Purchase": 6213,
    "Cancel": 1988,
    "Change": 3702,
    "Renewal": 5934
  }
]

What you need is using a $ wildcard within a shift transformation spec in order to replicate the current attributes's key such as您需要在移位转换规范中使用$通配符来复制当前属性的键,例如

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "$": "[#2].product",// $ grabs the value after going tree one level up from the current level
        "*": "[#2].&"// keeps the current attributes conforming to the objects nested within a common array 
      }
    }
  }
]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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