A simple but useful data of the world (by country) each in JSON format.
Using npm
$ npm install country-json
Using git
$ git clone https://github.com/samayo/country-json
Using composer
$ composer require samayo/country-json
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) {
var_dump($value); // { country: 'Afghanistan', city: 'Kabul' ..}
}
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' }
});
require 'json'
file = File.read('./src/country-capital-city.json')
json = JSON.parse(file)
puts json[0] # {"country"=>"Afghanistan", "city"=>"Kabul"}
import yaml
with open('./src/country-capital-city.json') as json_file:
for line in yaml.safe_load(json_file):
print line # {'country': 'Afghanistan', 'city': 'Kabul'}
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
)
func main() {
data, err := ioutil.ReadFile("path/to/country-capital-city.json")
if err != nil {
panic(err)
}
var entries []struct{ Country, City string }
if err = json.Unmarshal(data, &entries); err != nil {
panic(err)
}
for _, entry := range entries {
fmt.Println(entry.Country, entry.City) # {'country': 'Afghanistan', 'city': 'Kabul'}
}
}
- Countries by Name
- Countries by Abbreviation
- Countries by Average Male Height
- Countries by Alphabetical Letters
- Countries by Coastline Length
- Countries by Average Land Elevation
- Countries by National Dish (official/proposed)
- Countries by International Calling Code
- Countries by Capital City
- Countries by Continental Location
- Countries by Currency Name & Code
- Countries by TLD
- Countries by Flag in base64 format (experimental)
- Countries by Geo-Coordinates
- Countries by Government Type
- Countries by Independence Year
- Countries by ISO Code
- Countries by Landlocked Status
- Countries by Life Expectancy
- Countries by National Animal/Plant
- Countries by Population
- Countries by Population Density
- Countries by Region Location
- Countries by Surface Area
- Countries by Yearly avg Temperature
- Countries by Barcode Prefix
Feel free to send a PR anytime, any help or correction is appreciated.
For non-minor changes about country (ex: name, languages, capital-city, independence date..), please include a source, if possible.