I have the following data in a .json file:
{
"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"
}
}
}
}
and need to come up with a way to create this object from it:
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 app that will be consuming this data is written in Vue so using JavaScript to accomplish this would make sense, although my preference is to not use any third party libraries. Specifically, I'm interested in a programmatic approach that doesn't require hard coding of to manually create objects for currency
, majorLanguage
, landArea
. I don't really know how to start tackling this so don't have any sample attempts to post here.