I am trying to write a jolt transformation with the below input:
{
"data": {
"positions": {
"positionEdge": [
{
"position": {
"ref": "B125AE024:1:BASE",
"catalogue": {
"ref": "BASE:1"
}
},
"cursor": "Y3Vyc29yOi0tLWMxMWYxYWQwLTE2MWEtNDNmNS05ZDM5LWMwODRiZTdiN2Q3OV9fMTY1NzQ5NTU5MTQ4Ng=="
},
{
"position": {
"ref": "B125AE024:2:AGGREGATE",
"catalogue": {
"ref": "ATS:1"
}
},
"cursor": "Y3Vyc29yOi0tLWVmZDgwNTljLWYyNTctNDhhYy1hYzVlLWI3NzlhMjMyMTVmYl9fMTY1NzQ5NTU5MTI3MQ=="
}
],
"pageInfo": {
"hasNextPage": true
}
}
}
}
The expected output is:
[
{
"ref": "B125AE024:1:BASE",
"catalogueRef": "BASE:1"
},
{
"ref": "B125AE024:2:AGGREGATE",
"catalogueRef": "ATS:1"
}
]
My current spec is:
[
{
"operation": "shift",
"spec": {
"data": {
"positions": {
"positionEdge": {
"*": {
"position": {
"@": ".",
"catalogue": {
"ref": "catalogueRef"
}
}
}
}
}
}
}
},
{
"operation": "remove",
"spec": {
"*": {
"catalogue": ""
}
}
}
]
which does not give me the desired result and is missing the catalogueRef of the 2nd record..
Can the result be achieved in a single transformation, i.e. rename the catalogue.ref
field up and rename it to catalogueRef
? I basically want to flatten the position records.
Your help would be much appreciated.
2
Answers
Here’s the spec to get the desired output
the demo on the site http://jolt-demo.appspot.com/ is
Yes, you can use a single shift transformation spec, by walking through the
"positionEdge"
array, in a symbolical manner such asthe demo screenshot on the site http://jolt-demo.appspot.com/ (the famous sandbox of the jolt) is :
If the capital letter R is really needed, then you can convert the leaf node from
to