简体   繁体   English

JSON object 与 JOLT 排列

[英]JSON object to array with JOLT

I have the following JSON object我有以下 JSON object

Input:输入:

{
  "17.39.108.85:80": [],
  "10.204.32.9:443": [
    {
      "status": "DOWN"
    }
  ]
}

and trying to transform it into a list/array as below:并尝试将其转换为如下列表/数组:

Desired Output:所需 Output:

[
  {
    "17.39.108.85:80": []
  },
  {
    "10.204.32.9:443": [
      {
        "status": "DOWN"
      }
    ]
  }
]

What's the best way to use Jolt.使用 Jolt 的最佳方式是什么。

You can use this spec:您可以使用此规范:

Currently, your input is correct, but you need to put each key into an array.目前,您的输入是正确的,但您需要将每个键放入一个数组中。

You can get each key in the object and send it to an array with [#2] .您可以获取 object 中的每个键并将其发送到带有[#2]的数组。

Note: #2 is the index of each key.注意: #2是每个键的索引。 for example: 17.39.108.85:80 is 0 and 10.204.32.9:443 is 1 .例如: 17.39.108.85:80010.204.32.9:4431

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "@": "[#2].&"
      }
    }
  }
]

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

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