I am trying to transform a JSON into another JSON using JOLT.
My source JSON has the following format (the number of levels of child modules is not known):
Input
{
"modules": [
{
"id": "1",
"modules": [
{
"id": "1.1",
"modules": []
},
{
"id": "1.2",
"modules": [
{
"id": "1.2.1",
"modules": []
}
]
}
]
},
{
"id": "2",
"modules": [
{
"id": "2.1",
"modules": []
}
]
}
]
}
My JOLT transformation spec looks like this:
Spec:
The output I get is:
[
{
"operation": "shift",
"spec": {
"modules": {
"*": {
"id": "new_modules[&1].id"
}
}
}
}
]
Desired Output:
{
"new_modules": [
{
"id": "1"
},
{
"id": "1.1"
},
{
"id": "1.2"
},
{
"id": "1.2.1"
},
{
"id": "2"
},
{
"id": "2.1"
}
]
}
I am adding some unrelated text below as StackOverflow complains that my question is mostly code and that I must add more details. Kindly let me know if I am missing details.
2
Answers
You can use this spec:
You can’t have infinite levels in the jolt. But you can increase your levels in the above code.
You can use such a shift transformation spec
considering a JSON value with a 3 level of deepness at most.