1. The following JSON data is retrieved from another API, with country and flag displayed in separate Array objects
{
"data": [
{
"service": "Tourist Visa",
"service_id": 2,
"country_id": 2,
"country_name": "Australia",
"country_flag": "https://getset-visa.s3.amazonaws.com/images/flag/australia-flag.JPG"
},
{
"service": "Tourist Visa",
"service_id": 2,
"country_id": 1,
"country_name": "India",
"country_flag": "https://getset-visa.s3.amazonaws.com/images/countries/Indian-Flag.png"
},
{
"service": "Visa Services",
"service_id": 3,
"country_id": 1,
"country_name": "India",
"country_flag": "https://getset-visa.s3.amazonaws.com/images/countries/Indian-Flag.png"
}
]
}
2. For better consumption in an API using JavaScript, I aim to restructure the data as follows. Each country's information will be in a separate array object containing country name, flag, and services array
{
"data": [
{
"countryName": "Australia",
"countryFlag": "https://getset-visa.s3.amazonaws.com/images/flag/australia-flag.JPG",
"services": [
{
"serviceName": "Tourist Visa"
}
]
},
{
"countryName": "India",
":countryFlag": "https://getset-visa.s3.amazonaws.com/images/countries/Indian-Flag.png",
"l "services": [
{
"serviceName": "Visa Services"
},
{
"serviceName": "Tourist Visa"
}
]
}
]
}
Appreciate any assistance.