1
votes

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

1 Answers

2
votes

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