How we can make a dynamic key based on value in Jolt?
JSON input is like
{
"Rating": 1,
"SecondaryRatings": {
"Design": 4,
"Price": 2,
"RatingDimension3": 1
}
}
And expected output should be like
{
"rating-primary-1" : 1,
"rating-Design-4" : 4,
"rating-Price-2" : 2,
"rating-RatingDimension3-1" : 1
}
Current Spec is
[
{
"operation": "shift",
"spec": {
"Rating": "rating-primary",
"SecondaryRatings": {
"*": "rating-&"
}
}
}
]
CodePudding user response:
You can use two consecutive shift transformation specs such as
[
{
// determine object tags with desired prefixes
"operation": "shift",
"spec": {
"Rating": "rating-primary-.@(1,&)",
"SecondaryRatings": {
"*": "rating-&-.@(1,&)"
}
}
},
{
// then combine those keys with attribute keys inside each object
"operation": "shift",
"spec": {
"*": {
"*": "&1&"
}
}
}
]