Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
bonatoc opened this issue Nov 24, 2016 · 8 comments
Open

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

bonatoc opened this issue Nov 24, 2016 · 8 comments

Comments

@bonatoc
Copy link

bonatoc commented Nov 24, 2016

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
Copy link
Owner

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

@senyaak
Copy link

senyaak commented Jul 18, 2018

Object.getOwnPropertyNames(json)
Object.keys(json)
for(let key in json) {
  // ...
}

will do the thing - no need for changing the structure

@kawerewagaba
Copy link

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

@umpirsky
Copy link
Owner

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

@kawerewagaba
Copy link

How did I miss that? Thanks for that.

@TrejGun
Copy link

TrejGun commented May 26, 2019

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

@Peter-Optiway
Copy link

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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants