Question on JSON Transformation
I have a request JSON object as follows:
def request = {
"Items": [
{
"id": "151",
"optionNumber": 1,
"ListItems": [
{
"language": "en",
"value": "Aruba"
},
{
"language": "en-gb",
"value": "Arubagb"
},
{
"language": "fr-fr",
"value": ""
}
]
},
{
"id": "152",
"optionNumber": 2,
"ListItems": [
{
"language": "en",
"value": "Afganistan"
},
{
"language": "en-us",
"value": ""
}
]
}
]
}
Each item in the ListItems array contains a language and a value. I need to generate an output array based on the language. The desired output structure is as follows:
{
"Response": [
{
"language": "en",
"optionValues": [
{
"optionNumber": 1,
"optionValue": "Aruba"
},
{
"optionNumber": 2,
"optionValue": "Afganistan"
}
]
},
{
"language": "en-gb",
"optionValues": [
{
"optionNumber": 1,
"optionValue": "Arubagb"
}
]
},
{
"language": "fr-fr",
"optionValues": [
{
"optionNumber": 1,
"optionValue": ""
}
]
}
]
}
Please guide me on how to transform the input JSON into the desired output structure.