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

如何通过Jolt转换移除值缺失的对应键?

Solution

To eliminate entries where the corresponding input value is missing, use this two-step Jolt transformation:

Corrected Jolt Spec

[
  {
    "operation": "shift",
    "spec": {
      "alldetails": {
        "classid": "Id_class",
        "teacherid": "Id_teacher",
        "schoolid": "Id_school"
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "*": {
        "$": "data[].source",
        "@": "data[#2].value"
      }
    }
  }
]

How It Works

  1. First Shift Operation: Maps input fields to their corresponding source names (e.g., classid → Id_class). Missing fields like teacherid are automatically excluded from this intermediate result.
  2. Second Shift Operation: Converts each key-value pair from the intermediate object into entries in the data array:
    • $ references the current key to set the source field
    • @ references the current value to set the value field
    • #2 ensures value is added to the same array entry as its matching source

Result Output

{
  "data": [
    {
      "source": "Id_class",
      "value": 1
    },
    {
      "source": "Id_school",
      "value": 3
    }
  ]
}

Content of the question is from Stack Exchange, asked by Vishavjeet

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.07 12:23:15