Created
April 30, 2019 12:43
-
-
Save thedamian/14213922b9127c8442b5b53f5345b647 to your computer and use it in GitHub Desktop.
convert population json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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