问题
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