json Jolt未打印任何内容

ev7lccsx  于 2023-06-07  发布在  其他
关注(0)|答案(1)|浏览(138)

我正在写jolt来转换这些数据,但是没有得到想要的结果
如果practice_locprac_numtopId对于两个或多个数据是相同的,则它们将与subList内的单独的S1S2组合在一起。否则,它们将通过,因为它是只添加子列表。

数据

[
  {
    "practice_loc": "120",
    "prac_num": "oswal",
    "topId": "t1",
    "S1": "A1",
    "S2": "B1"
  },
  {
    "practice_loc": "120",
    "prac_num": "oswal",
    "topId": "t1",
    "S1": "A2",
    "S2": ""
  },
  {
    "practice_loc": "334",
    "prac_num": "L3",
    "topId": "plumcherry",
    "S1": "A3",
    "S2": ""
  },
  {
    "practice_loc": "987",
    "prac_num": "L3",
    "topId": "artica",
    "S1": "A5",
    "S2": "B7"
  }
]

预期输出:

[
  {
    "practice_loc": "120",
    "prac_num": "oswal",
    "topId": "t1"
    "subList": [
      {
        "S1": "A1",
        "S2": "B1"
      },
      {
        "S1": "A2",
        "S2": ""
      }
    ]
  },
  {
    "practice_loc": "334",
    "prac_num": "L3",
    "topId": "plumcherry"
    "subList": [
      {
        "SubID1": "A3",
        "SubID2": ""
      }
    ]
  },
  {
    "practice_loc": "987",
    "prac_num": "L3",
    "topId": "artica",
    "subList": [
      {
        "SubID1": "A5",
        "SubID2": "B7"
      }
    ]
  }
]

这是我尝试过的,但没有得到预期的结果,它不打印任何东西

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "@": "@(1,practice_loc).@(1,prac_num).@(1,topId)"
      }
    }
  },
  {
    "operation": "cardinality",
    "spec": {
      "*": {
        "*": "MANY"
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "*": {
        "*": {
          "*": {
            "practice_loc": "[#4].&",
            "prac_num": "[#4].&",
            "topId": "[#4].&",
            "S*": "[#4].subList[&1].&"
          }
        }
      }
    }
  },
  {
    "operation": "cardinality",
    "spec": {
      "*": {
        "practice_loc": "ONE",
        "prac_num": "ONE",
        "topId": "ONE"
      }
    }
  }
]
wn9m85ua

wn9m85ua1#

你现在的技术水平相当不错。会适合这样重新排列

[
  { // group by those three attributes
    "operation": "shift",
    "spec": {
      "*": {
        "*": "@1,practice_loc.@1,prac_num.@1,topId.&",
        "S*": "@1,practice_loc.@1,prac_num.@1,topId.subList[&1].&"
      }
    }
  },
  { // get rid of wrappers
    "operation": "shift",
    "spec": {
      "*": {
        "*": {
          "*": {
            "@": ""
          }
        }
      }
    }
  },
  {
    "operation": "cardinality",
    "spec": {
      "*": {
        "*": "ONE", // pick only single one from repeating components 
        "subList": "MANY"
      }
    }
  },
  { // get rid of generated nulls within subList arrays 
    "operation": "modify-overwrite-beta",
    "spec": {
      "*": "=recursivelySquashNulls"
    }
  }
]

编辑*用于说明 *:下面,我已经粘贴了图像,我在切换Configure部分的ADVANCED选项卡后得到了JoltTransformJSON处理器的版本1.21.0作为NiFi。顺便说一句,你的也是最近的版本。

相关问题