首页 > 解决方案 > 在 JOLT 中验证和转换数组对象

问题描述

希望根据输入数组中的活动状态输出 JSON。如果活动为真,则提供值对象。输入 :

{
  "services": [
    {
      "active": true,
      "value": "Clampable",
      "key": "40300"
    },
    {
      "active": false,
      "value": "Mixed load",
      "key": "40302"
    }
]
}

眼镜:

[
  {
    "operation": "shift",
    "spec": {
      "services": {
        "*": {
          "key": {
            "40302": {
              "#mixed": "loading_method"
            },
            "40300": {
              "#clampable": "loading_method"
            }
          }
        }
      }
    }
  }
]

输出 :

"loading_method" : [ "clampable", "mixed"]

我不希望混合值作为输出,因为状态为假。任何建议都会很棒..

标签: jsonjolt

解决方案


这行得通,

如果 active 为真,则移动值节点。

[
  {
    "operation": "shift",
    "spec": {
      "services": {
        "*": {
          "active": {
            "true": {
              "@(2,value)": "loading_method"
            }
          }
        }
      }
    }
  }
]

推荐阅读