======================================= A simple but useful data of the world (by country) in JSON formats.
Using git
$ git clone https://github.com/samayo/country.json
Below, You'll find examples using various languages to integrate/display the data.
<?php
$file = file_get_contents("/src/country-capital-city.json");
$data = json_decode($file, true);
foreach ($data as $key => $value) {
list($country, $city) = $value;
// initialize your database ..
$db->query("INSERT INTO countries (country, city) VALUES ($country, $city)");
}
var fs = require('fs');
fs.readFile('./src/country-capital-city.json', 'utf8', function(err, cities) {
try {
cities = JSON.parse(cities);
} catch (e) {
console.log('error parsing JSON', e);
}
console.log(cities[0]); // { country: 'Afghanistan', city: 'Kabul' }
});
So contributions are welcome. Feel free to PR anything.
If you are fixing a minor typo or something similar, you can do a PR anytime. However, for bigger Changes like country and/or city names, language, population change .. then please include a source, if possible.
MIT