I have a below json, from which I want to extract the another json using jolt. Using JOLT transform demo website, I am able to coin some spec but it doesnt gives me the exact json I want.
{
"status": "OK",
"recordCount": 26,
"startTimestamp": "2017-08-08T04:49:31.3860406Z",
"endTimestamp": "2017-08-08T04:49:31.8860442Z",
"timeTaken": 0.5000036,
"apiResults": [
{
"sportId": 28,
"name": "Olympics",
"league": {
"leagueId": 442,
"name": "Winter Olympics",
"abbreviation": "WNTR_OLY",
"displayName": "Winter Olympics",
"season": {
"season": 2014,
"isActive": null
},
"medals": [
{
"olympicCountry": {
"countryId": 1000,
"name": "Russian Federation",
"abbreviation": "RUS"
},
"medalCount": {
"gold": 13,
"silver": 11,
"bronze": 9,
"total": 33
}
},
{
"olympicCountry": {
"countryId": 8673,
"name": "Russian Federation",
"abbreviation": "RUS"
},
"medalCount": {
"gold": 13,
"silver": 11,
"bronze": 9,
"total": 33
}
}
]
}
}
]
}
I want to transform it in to
{
"data" : [
{
"countryCode" : 1000,
"countryName" : "Russian Federation",
"medals" : {
"gold" : 13,
"silver" : 11,
"bronze" : 9,
"total" : 33
}
},
{
"countryCode": 8673,
"countryName": "Russian Federation",
"medals": {
"gold" : 13,
"silver" : 11,
"bronze" : 9,
"total" : 33
}
}
]
}
The spec so far i could figure out is
[
{
"operation": "shift",
"spec": {
"apiResults": {
"*": {
"league": {
"medals": {
"*": {
"olympicCountry": {
"countryId": "data.countryCode",
"name": "data.countryName"
},
"medalCount": "data.medals"
}
}
}
}
}
}
}
]
This spec is close enough but not accurate. It generates
{
"data" : {
"countryCode" : [ 1000, 8673 ],
"countryName" : [ "Russian Federation", "Russian Federation" ],
"medals" : [ {
"gold" : 13,
"silver" : 11,
"bronze" : 9,
"total" : 33
}, {
"gold" : 13,
"silver" : 11,
"bronze" : 9,
"total" : 33
} ]
}
}
Any hint will be much appreciated.