【问题标题】:jolt concatenate array elements to single objectjolt 将数组元素连接到单个对象
【发布时间】:2018-08-31 12:05:57
【问题描述】:

我从 Jolt 开始,但我无法将数组的元素连接到单个字符串,

我有这样的json:

{
  "partNb": "1234",
  "partDescriptions": [
    {
      "country": "GB",
      "language": "en",
      "content": "1 tool description in en_GB"
    },
    {
      "country": "GB",
      "language": "en",
      "content": "2 tool description in en_GB"
    }
  ]
}

并带有颠簸规范:

[
  {
    "operation": "shift",
    "spec": {
      "partNb": "id",
      "partDescriptions": {
        "*": {
          "content": "description"
        }
      }
    }
  }
]

为此,我有这个输出:

{
  "id" : "1234",
  "description" : [ "1 tool description in en_GB", "2 tool description in en_GB" ]
}

但是如何得到这样的结果呢?:

{
  "id" : "1234",
  "description" :  "1 tool description in en_GB , 2 tool description in en_GB" 
}

【问题讨论】:

    标签: json jolt


    【解决方案1】:

    规格

    [
      {
        "operation": "modify-overwrite-beta",
        "spec": {
          "description": "=join(', ',@(1,description))"
        }
      }
    ]
    

    【讨论】:

    • 感谢您的回答,但结果是:“description”:“{country=GB, language=en, content=1 tool description in en_GB}, {country=GB, language=en, content=2 en_GB} 中的工具描述"
    【解决方案2】:

    仅获取连接到描述中的内容字段:

    [
      {
        "operation": "shift",
        "spec": {
          "partDescriptions": {
            "*": {
              "content": {
                "@": "content"
              }
            }
          }
        }
      },
      {
        "operation": "modify-overwrite-beta",
        "spec": {
          "description": "=join(', ', @(2,content))"
        }
      }
    ]
    
    

    输出:

    {
      "content" : [ "1 tool description in en_GB", "2 tool description in en_GB" ],
      "description" : "1 tool description in en_GB, 2 tool description in en_GB"
    }
    
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-01-19
      • 1970-01-01
      • 2022-11-24
      • 1970-01-01
      • 2023-02-06
      • 2020-06-22
      • 2021-09-11
      • 1970-01-01
      相关资源
      最近更新 更多