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

Jolt Shift转换数组输出出现Null,求修正方案

Fixing Null Values in Jolt Transformation's LOCATIONS Array

Hey there! I see the annoying null value popping up in your second object's LOCATIONS array—let's get this sorted out right away.

The Root Cause

The issue comes from how you're indexing the LOCATIONS array in your shift spec. Right now you're using [&1] for the LOCATIONS index:

"BUILDING": "[&1].LOCATIONS.[&1].Building",

That inner &1 refers to the index of the parent COMPINFO array element. For the first COMPINFO entry (index 0), this maps to LOCATIONS[0] which works perfectly. But for the second entry (index 1), it tries to map to LOCATIONS[1]—leaving the LOCATIONS[0] slot empty, which gets filled with null.

The Simple Fix

Since each COMPINFO entry should only have one location object in its LOCATIONS array, replace the inner [&1] with a fixed [0] index. Here's the corrected spec:

[
  {
    "operation": "shift",
    "spec": {
      "data": {
        "COMPINFO": {
          "*": {
            "COMPID": "[&1].COMPID",
            "ORGID": "[&1].ORGID",
            "COMP_DESC": "[&1].DESCRIPTION",
            "BUILDING": "[&1].LOCATIONS.[0].Building",
            "FLR_LEVEL": "[&1].LOCATIONS.[0].Floor_Level",
            "ROOM_SPCE": "[&1].LOCATIONS.[0].ROOM_SPCE",
            "SITEID": "[&1].SITEID",
            "ASSETTYPE": "[&1].ASSETTYPE"
          }
        }
      }
    }
  }
]

Verified Output

With this adjusted spec, your output will match exactly what you expected:

[
  {
    "COMPID": "C2014",
    "ORGID": "",
    "DESCRIPTION": "Cherokee High School",
    "LOCATIONS": [
      {
        "Building": "Main",
        "Floor_Level": "Ground",
        "ROOM_SPCE": "100"
      }
    ],
    "SITEID": "BWDEMO",
    "ASSETTYPE": "MANUFACTURING"
  },
  {
    "COMPID": "9001B",
    "ORGID": "",
    "DESCRIPTION": "Sludge Pump",
    "LOCATIONS": [
      {
        "Building": "Main",
        "Floor_Level": "Production",
        "ROOM_SPCE": "100"
      }
    ],
    "SITEID": "BWDEMO",
    "ASSETTYPE": "FACILITY"
  }
]

No more unwanted nulls—each LOCATIONS array now holds exactly one location object as intended!

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.27 07:19:28