简体   繁体   中英

JOLT transformation for nested JSON?

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.

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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM