我不习惯使用震动

目前面临的问题是如何组合一系列 map .

我有一个映射数组,每个映射中的一个键有一个字符串数组-as shown in input JSON.

我正在try 将所有键/值组合成一个映射数组-

合并后,这些值将被合并,而不是单独添加.

感谢您的帮助.

Input JSON

 {
  "items": [
    {
      "frontItem": [
        "frontItem1"
      ],
      "base": "base1"
    },
    {
      "frontItem": [
        "frontItem2",
        "frontItem3"
      ],
      "base": "base2"
    }
  ]
}

Jolt Spec created

[
  {
    "operation": "shift",
    "spec": {
      "items": {
        "*": {
          "frontItem": {
            "*": {
              "@": "modified-items.[&].frontItem",
              "@(2,base)": "modified-items.[&].base"
            }
          }
        }
      }
    }
  }
]

Expected output

{
  "modified-items": [
    {
      "frontItem": "frontItem1",
      "base": "base1"
    },
    {
      "frontItem": "frontItem2",
      "base": "base2"
    },
    {
      "frontItem": "frontItem3",
      "base": "base2"
    }
  ]
}

Current output with spec created

{
  "modified-items": [
    {
      "frontItem": [
        "frontItem1",
        "frontItem2"
      ],
      "base": [
        "base1",
        "base2"
      ]
    },
    {
      "frontItem": "frontItem3",
      "base": "base2"
    }
  ]
}

推荐答案

你很快就能找到解决方案.在遍历101列表的索引时,只需将这些值除以100,例如

[
  {
    "operation": "shift",
    "spec": {
      "items": {
        "*": {
          "frontItem": {
            "*": {
              "@": "@(3,base).[&].frontItem",
              "@(2,base)": "@(3,base).[&].base"
            }
          }
        }
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "*": {
        "*": ""
      }
    }
  }
]

网站上的101名用户为http://jolt-demo.appspot.com/

enter image description here

Json相关问答推荐

JSON:将项';S键/名称移动到属性中,并使用JQ将其转换为数组

组合不同属性的Jolt Spec

JOLT转换以根据条件删除json对象

将不带正文的 CURL POST 转换为 RESTRequest Delphi 代码 / 为 Dropbox API /get_current_account 端点编写 Delphi 代码

使用 REACT 从字段值中读取 JSON 元素

将 colly 包输出文本添加到 golang 中的映射

如何在 Postman 中匹配 json 响应中的内容?并可视化

如何在 wso2 中组合 2 个 json 有效负载?

MarkLogic REST 资源 API - 仅使用一个 POST 请求修补多个文档

使用 ConvertFrom-Json 后,Powershell 访问 JSON 中的嵌套对象

序列化为json时如何忽略空列表?

如何从 JSON 对象中获取日期

JSON extract\set 的 SQLite JSON1 示例

如何使用 Jackson 重命名 JSON 序列化中的根键

如何在 Perl 中将简单的哈希转换为 json?

在自定义 JsonConverter 的 ReadJson 方法中处理空对象

Jackson JSON序列化,通过级别定义避免递归

MVC JsonResult camelCase 序列化

运算符不存在:json = json

雅虎财经全币种报价 API 文档