我正在处理Jolt变换,但我无法实现所需的输出.

Json输入-

{
  "297410879665": {
    "i-06e33d65e1656d9a0": {
      "metrics": {
        "Datapoints": [
          {
            "Average": 34.054385397049664,
            "Timestamp": "2024-01-17 05:58:00+00:00",
            "Unit": "Percent"
          },
          {
            "Average": 34.06279805089895,
            "Timestamp": "2024-01-18 05:58:00+00:00",
            "Unit": "Percent"
          }
        ],
        "Label": "CPUUtilization",
        "ResponseMetadata": {
          "HTTPHeaders": {
            "content-length": "669",
            "content-type": "text/xml",
            "date": "Wed, 31 Jan 2024 11:24:42 GMT",
            "x-amzn-requestid": "0ad2ed7f-5555-4a51-b038-74127bd1efac"
          },
          "HTTPStatusCode": 200,
          "RequestId": "0ad2ed7f-5555-4a51-b038-74127bd1efac",
          "RetryAttempts": 0
        }
      }
    },
    "i-0ad1fb9baaf18c531": {
      "metrics": {
        "Datapoints": [],
        "Label": "CPUUtilization",
        "ResponseMetadata": {
          "HTTPHeaders": {
            "content-length": "337",
            "content-type": "text/xml",
            "date": "Wed, 31 Jan 2024 11:24:38 GMT",
            "x-amzn-requestid": "42f2dfaf-04c0-48c7-93bf-ccc8fbe4394d"
          },
          "HTTPStatusCode": 200,
          "RequestId": "42f2dfaf-04c0-48c7-93bf-ccc8fbe4394d",
          "RetryAttempts": 0
        }
      }
    },
    "i-0b82b815caf164734": {
      "metrics": {
        "Datapoints": [
          {
            "Average": 2.0358126491612563,
            "Timestamp": "2024-01-17 05:58:00+00:00",
            "Unit": "Percent"
          },
          {
            "Average": 2.057291212227385,
            "Timestamp": "2024-01-18 05:58:00+00:00",
            "Unit": "Percent"
          }
        ],
        "Label": "CPUUtilization",
        "ResponseMetadata": {
          "HTTPHeaders": {
            "content-length": "669",
            "content-type": "text/xml",
            "date": "Wed, 31 Jan 2024 11:24:41 GMT",
            "x-amzn-requestid": "d427e857-7c3a-4548-8206-905cd93dc437"
          },
          "HTTPStatusCode": 200,
          "RequestId": "d427e857-7c3a-4548-8206-905cd93dc437",
          "RetryAttempts": 0
        }
      }
    }
  }
}```

question- how to loop through multiple sub arrays and retrieve only instance id and its respective datapoints. There are a lot of sub arrays without instanceId but we need only instance id and the content in subarray.

required output-
get the account id which is in the first line, and include it in the output array with instance id , average and timestamp.

[ { "Account_id":"297410879665", "INSTANCE_ID":"i-06e33d65e1656d9a0", "平均值":"34.0627", "Timestamp":"2024-01-18 05:58:00+00:00", "单位":"百分比" }, { "Account_id":"297410879665", "实例id":"i-0b82b815af164734", "平均值":"34.0627", "Timestamp":"2024-01-18 05:58:00+00:00", "单位":"百分比" } ]


note- 
kindly look into this and give possible jolt spec or even give any ideas on how to approach this. Please comment if you have any doubts regarding the input and output.
I will reply to your comment as soon as possible 


Thanks in advance.

推荐答案

以下规格是否为您提供了所需的输出:

[
  {
    "operation": "shift",
    "spec": {
      "*": { //accountId
        "*": { //instanceId
          "metrics": {
            "Datapoints": {
              "*": "[].&4_&3_&"
            }
          }
        }
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "*": {
        "*_*_*": {
          "$(0,1)": "[&2].account_id",
          "$(0,2)": "[&2].instance_id",
          "*": "[&2].&"
        }
      }
    }
  }
]

Json相关问答推荐

SWIFT中的网络经理

Allof Indide的JSON模式之一

使用PowerShell解析文件并获取特定行的值

在MongoDB中检索某个月份和年份的JSON文档

基于 JSON 字段的 Jolt 条件标志

Python 将 struct 化文本转换和筛选为对象

根据值过滤输入的JSON并使用它准备预期的输出

使用 map_values Select 包含空格的字符串未按预期工作

将 JSON 字符串解析为 Kotlin Android 中的对象列表(MOSHI?)

从 PySpark 中的复杂 JSON 文件中高效清除 HTML 实体

通过一个序列化器更新多个模型数据

N1QL 搜索对象内的某些对象

如何在 Go 中生成带有排序键的 JSON?

IE8 原生 JSON.parse 错误导致堆栈溢出

将 JSON 对象推送到 localStorage 中的数组

在 Webpack 中加载静态 JSON 文件

java.lang.BootstrapMethodError:调用站点#4 bootstrap 方法的异常,初始化 retrofit 时

通过 JSON 发送 64 位值的公认方式是什么?

Jersey 2.0 相当于 POJOMappingFeature

JSON.stringify 向我的 Json 对象添加额外的 \ 和 "" 的问题