json 如何在JOLT中使用key的值

eanckbw9  于 2023-02-01  发布在  其他
关注(0)|答案(2)|浏览(148)

我正在寻找打破嵌套的JSON文件,并试图将它们扁平化,以适应SQL数据库。

当前JSON:

{
  "content": {
    "failedPerProductLineAndReason": {
      "Product1": {
        "Downsizing licenses is not allowed": 1
      }
    }
  }
}

预期成果:

{
  "ErrorType": "failedPerProductLineAndReason",
  "product": "Product1",
  "error": "Downsizing licenses is not allowed",
  "quantity": 1
}
ccrfmcuu

ccrfmcuu1#

进入Downsizing licenses is not allowed并通过@获取其值,然后通过$获取您想要的另一个密钥

[
  {
    "operation": "shift",
    "spec": {
      "*": { // content
        "*": { // failedPerProductLineAndReason
          "*": { // Product1
            "*": { // Downsizing licenses is not allowed
              "$2": "ErrorType",
              "$1": "product",
              "$": "error",
              "@": "quantity"
            }
          }
        }
      }
    }
  }
]
8wtpewkr

8wtpewkr2#

您可以在对象/属性中使用**$**通配符,如

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "*": {
          "$": "ErrorType",
          "*": {
            "$": "product",
            "*": {
              "$": "error",
              "@": "quantity"
            }
          }
        }
      }
    }
  }
]

如主要需要提取密钥
站点http://jolt-demo.appspot.com/上的演示是

相关问题