You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

请求协助实现JOLT转换:拆分含Tags子数组的记录

JOLT转换方案:展开Tags子数组并整合字段

需求说明

将输入对象中包含的Tags子数组展开,每个数组元素对应一个独立的输出对象;同时保留原对象的Size、SnapshotId、State字段,并将Tags元素中的Key/Value重命名为Tags_Key/Tags_Value。

JOLT转换规范

[
  {
    "operation": "shift",
    "spec": {
      "Tags": {
        "*": {
          "@2,Size": "[&1].Size",
          "@2,SnapshotId": "[&1].SnapshotId",
          "@2,State": "[&1].State",
          "Key": "[&1].Tags_Key",
          "Value": "[&1].Tags_Value"
        }
      }
    }
  }
]

转换逻辑解释

  1. 遍历Tags数组:通过Tags.*匹配Tags数组中的每一个元素
  2. 复制顶层字段:@2,Size表示从当前元素位置向上回溯2层(到顶层对象)获取Size的值,[&1]表示将值存入输出数组对应索引的对象中,同理处理SnapshotId和State
  3. 重命名Tags字段:直接将当前Tags元素的Key和Value映射为Tags_Key和Tags_Value,存入对应索引的输出对象

输入输出验证

输入

{
  "Size": 200,
  "SnapshotId": "",
  "State": "in-use",
  "Tags": [
    {
      "Key": "BusinessUnit",
      "Value": "Platform"
    },
    {
      "Key": "DR",
      "Value": "Critical"
    }
  ]
}

输出

[
  {
    "Size": 200,
    "SnapshotId": "",
    "State": "in-use",
    "Tags_Key": "BusinessUnit",
    "Tags_Value": "Platform"
  },
  {
    "Size": 200,
    "SnapshotId": "",
    "State": "in-use",
    "Tags_Key": "DR",
    "Tags_Value": "Critical"
  }
]

内容的提问来源于stack exchange,提问作者priyanka

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.15 12:45:04