umpirsky / country-list

:globe_with_meridians: List of all countries with names and ISO 3166-1 codes in all languages and data formats.
MIT License
5.18k stars 1.55k forks source link

JSON is kind of useless unless it has proper key/values #62

Open bonatoc opened 8 years ago

bonatoc commented 8 years ago

With JS frameworks, and more generally REST APIs/HTTP requests, the current JSON structures are not much help, since we can't programmatically target keys.

How about this structure?

[
    { 
        id: 'AF', 
        value:'Afghanistan' 
    },
    {
        id: 'ZA', 
        value:'Afrique du Sud' 
    },
...
]
umpirsky commented 8 years ago

I agree, good idea for next major release, thanks.

senyaak commented 6 years ago
Object.getOwnPropertyNames(json)
Object.keys(json)
for(let key in json) {
  // ...
}

will do the thing - no need for changing the structure

kawerewagaba commented 6 years ago

It is also easy to iterate over with foreach() in php, of course after a json_decode(), so I guess the format stays.

umpirsky commented 6 years ago

@ckwagaba There is https://github.com/umpirsky/country-list/blob/master/data/en/country.php for PHP. No need to json decode.

kawerewagaba commented 6 years ago

How did I miss that? Thanks for that.

TrejGun commented 5 years ago

this new format is usefull only if it contains some other data for example flag or list of locales

Peter-Optiway commented 5 years ago
Object.getOwnPropertyNames(json)
Object.keys(json)
for(let key in json) {
  // ...
}

will do the thing - no need for changing the structure

Or you could use Object.entries example:

Object.entries(json).map(([key, value]) => key + " - " + value);
630Studios commented 3 years ago

No seriously. The format of the JSON data is absolutely horrific. Why would anyone think this is a good idea?