【问题标题】:JOLT : Convert one property of an array into a comma separated stringJOLT : 将数组的一个属性转换为逗号分隔的字符串
【发布时间】:2019-04-10 07:00:07
【问题描述】:

使用震动

我需要将标签数组中的名称转换为逗号分隔的字符串集作为标签。

输入:

tags : [
{
"id" : "1",
"name": "mobile",
"slug": ""
},
{
"id" : "2",
"name": "smart phone",
"slug": ""
},
{
"id" : "3",
"name": "light-weight",
"slug": ""
}
]

输出:

标签:“移动、智能手机、轻量级”

预期的规范应该是什么?

【问题讨论】:

    标签: arrays jolt


    【解决方案1】:
    [
      {
        "operation": "shift",
        "spec": {
          "tags": {
            "*": {
              "name": "tags.[]"
            }
          }
        }
      }
    ]
    

    输出必须是 Json 将是:

    {
      "tags" : [ "mobile", "smart phone", "light-weight" ]
    }
    

    【讨论】:

    • @Behrouz Seyedi 所需的输出是逗号分隔的字符串,而不是字符串数组。
    • 如何反转上述转换?从字符串列表到地图/字典列表。
    【解决方案2】:

    这边。

    [
    {
    "operation": "shift",
    "spec": {
      "tags": {
        "*": {
          "name": "tags.[]"
        }
      }
     }
    },
    {
      "operation": "modify-overwrite-beta",
      "spec": {
      "tags": "=join(',',@(1,tags))"
      }
     }
    ]
    

    只需使用 join 方法以逗号分隔字段

    【讨论】:

      猜你喜欢
      • 2021-08-09
      • 2021-12-18
      • 1970-01-01
      • 2021-12-06
      • 1970-01-01
      • 2011-06-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多