过滤值取决于另一个字段

Filter values depends on another field

我在寻找使用 jolt 在我的输入 json 文件中过滤的正确方法时遇到了一些问题,如下所述:

输入:

{
  "test1": 2242,
  "test2": 23456,
  "description": "desc, desc, desc",
  "name1": "foo",
  "active": true,
  "date1": "xx-xx-xx",
  "date2": "xx-xx-xx",
  "grade": "A",
  "quantity": 10,
  "information": "info, info, info",
  "favorite": "Y",
  "maxValue": 100,
  "approachTypeMin[zone=MAR, method=a]": "12",
  "approachTypeMax[zone=MAR, method=a]": "50",
  "approachTypeMin[zone=NOR, method=b]": "3",
  "approachTypeMax[zone=NOR, method=b]": "10"
}

这是我的规格

[
  {
    "operation": "shift",
    "spec": {
      "test1": "value1",
      "test2": "value2",
      "description": "desc1",
      "name1": "nameValue",
      "active": {
        "true": {
          "#Active": "status"
        },
        "false": {
          "#Inactive": "status"
        }
      },
      "date1": "beginDate",
      "date2": "endDate",
      "grade": {
        "*": {
          "$": "testGrade.value",
          "@(2,type)": "testGrade.type",
          "#2": "testGrade.defaultValue"
        }
      },
      "quantity": "qtn",
      "additionalInfo": "information",
      "favorite": "fvt",
      "maxValue": "max",
      "approachType*, method=*]": "test.&(0,2)"
    }
  }
]

这是我的实际输出

{
  "value1" : 2242,
  "value2" : 23456,
  "desc1" : "desc, desc, desc",
  "nameValue" : "foo",
  "status" : "Active",
  "beginDate" : "xx-xx-xx",
  "endDate" : "xx-xx-xx",
  "testGrade" : {
    "value" : "A",
    "defaultValue" : "2"
  },
  "qtn" : 10,
  "fvt" : "Y",
  "max" : 100,
  "test" : {
    "A" : [ "12", "50" ],
    "B" : [ "3", "10" ]
  }
}

我的问题是我找不到一种方法来根据等级(例如等级 A==Approach 方法)获得类似上述结果的方法:

{
  "value1": 2242,
  "value2": 23456,
  "desc1": "desc, desc, desc",
  "nameValue": "foo",
  "status": "Active",
  "beginDate": "xx-xx-xx",
  "endDate": "xx-xx-xx",
  "value": "X",
  "testGrade": {
    "type": "A",
    "defaultValue": "2"
  },
  "qtn": "10",
  "fvt": "Y",
  "max": "100",
  "convertedApproachMin": 12,
  "convertedApproachMax": 50

}

感谢您的帮助!

需要将以approachType开头的键名再分割一次,以便通过MinMax将它们分开,以导出小写等级以匹配提取的方法(ab)。

因此,请使用以下规格:

[
  {
    "operation": "shift",
    "spec": {
      "test1": "value1",
      "test2": "value2",
      "description": "desc1",
      "name1": "nameValue",
      "active": {
        "true": {
          "#Active": "status"
        },
        "false": {
          "#Inactive": "status"
        }
      },
      "date1": "beginDate",
      "date2": "endDate",
      "grade": "&",
      "quantity": "qtn",
      "additionalInfo": "information",
      "favorite": "fvt",
      "maxValue": "max",
      "approachType*\[zone*, method=*]": "cA&(0,1).&(0,3)"
    }
  },
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "grade_l": "=toLower(@(1,grade))"
    }
  },
  {
    "operation": "shift",
    "spec": {
      "*": "&",
      "grade_l": {
        "*": {
          "@(2,grade)": "testGrade.value",
          "#2": "testGrade.defaultValue",
          "@(2,cAMin.&)": "convertedApproachMin",
          "@(2,cAMax.&)": "convertedApproachMax"
        }
      }
    }
  },
  {
    "operation": "remove",
    "spec": {
      "grade": "",
      "cA*": ""
    }
  }
]

网站上的 演示 http://jolt-demo.appspot.com/ :