JOLT transformation for nested JSON?

感情迁移 提交于 2021-01-28 12:20:21

问题


I have a JSON that looks like this :

{
"Level1": {
    "Level2": {
        "val1": "Test",
        "val2": "Val"
    }
}

}

When I apply the followng Jolt shift transformation to this :

[{
    "operation": "shift",
    "spec": {
        "Level1": {
            "Level2": {
                "val1": "val001",
                "val2": "val002"
            }
        }
    }
}]

I get the folliwng result :

    {
    "val001": "Test",
    "val002": "Val"
}

Why cant I see the Level1, Level2 in the output? Please an someone help, I want to see that in the output too similar to whats the input.


回答1:


The values in the shift spec usually refer to the location of the key in the output, so you'd need to include Level1 and Level2 in the values:

[{
  "operation": "shift",
  "spec": {
    "Level1": {
      "Level2": {
        "val1": "Level1.Level2.val001",
        "val2": "Level1.Level2.val002"
      }
    }
  }
}]

If Level1 and/or Level2 can be arbitrary, you can use the @ operator to "go back up the tree" and get the values (see the Shiftr javadoc for examples).



来源:https://stackoverflow.com/questions/49375313/jolt-transformation-for-nested-json

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!