Skip to content

Instantly share code, notes, and snippets.

@thedamian
Created April 30, 2019 12:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thedamian/14213922b9127c8442b5b53f5345b647 to your computer and use it in GitHub Desktop.
Save thedamian/14213922b9127c8442b5b53f5345b647 to your computer and use it in GitHub Desktop.
convert population json
const fs = require('fs');
let population = JSON.parse(fs.readFileSync('population.json','utf8'));
population = population.filter(c => c.Year == "2016");
population = population.map(c=> {return {code3:c['Country Code'],population:c.Value}});
population = population.filter(c => c != null);
let country3to2 = JSON.parse(fs.readFileSync('3to2countrycode.json','utf8'));
population = population.filter(c => c != null);
population = population.map(c=> {
let code2obj = country3to2.find(cc => cc['alpha-3'] == c.code3);
if (code2obj){
return {
code3: c.code3,
population: c.population,
code2: code2obj['alpha-2']
}
}
});
population = population.filter(c => c != null);
population = population.map(c => {
if (c) {
let obj = {};
obj[c.code2] = c.population;
return obj;
}
})
fs.writeFile('CountriesForGithub.json',JSON.stringify(population),() => {
console.log("done");
})
console.log(population);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment