In a .json file, I have data that includes information on countries such as their currency, major language, and land area in square kilometers or square miles.
{
"countries": {
"sweden": {
"currency": "Swedish krona",
"majorLanguage": "Swedish",
"landArea": {
"value": 410330,
"uom": "sq km"
}
},
"japan": {
"currency": "yen",
"majorLanguage": "Japanese",
"landArea": {
"value": 364500,
"uom": "sq km"
}
},
"unitedStatesOfAmerica": {
"currency": "US dollar",
"majorLanguage": "English",
"landArea": {
"value": 3796742,
"uom": "sq mi"
}
}
}
}
I am looking for a way to dynamically create an object from this data structure that organizes the information by currency, major language, and land area for each country:
Object {
"currency": Object {
"japan": "yen",
"sweden": "Swedish krona",
"unitedStatesOfAmerica": "US dollar"
},
"majorLanguage": Object {
"japan": "Japanese",
"sweden": "Swedish",
"unitedStatesOfAmerica": "English"
},
"landArea": Object {
"japan": Object {
"value": 364500,
"uom": "sq km"
},
"sweden": Object {
"value": 410330,
"uom": "sq km"
},
"unitedStatesOfAmerica": Object {
"value": 3796742,
"uom": "sq mi"
}
}
}
The application consuming this data is built with Vue, so using JavaScript to achieve this objective is ideal. However, I aim to avoid relying on any third-party libraries. I am interested in a systematic approach that doesn't involve manually creating objects for currency, major language, and land area. I currently don't have a starting point for tackling this challenge and therefore do not have any initial code snippets to share.