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

Poor JSON response structure #32

Closed
simpleshadow opened this issue Mar 11, 2019 · 13 comments
Closed

Poor JSON response structure #32

simpleshadow opened this issue Mar 11, 2019 · 13 comments

Comments

@simpleshadow
Copy link

simpleshadow commented Mar 11, 2019

Really dig what you've done @meetDeveloper! Was not aware that Google is using Oxford Dictionaries behind the scenes.

While I really dig the API, the current structure of the API responses makes it very unusable (at least in my JavaScript web-based client). Having values as keys is non-standard and iterating over them is a nightmare. For example, the meaning property should be an array and contain a standard object response with partOfSpeech (e.g. { "partOfSpeech": "noun", ... }).

I'd suggest a response that takes cues from the JSON:API spec.

Here's an example of the suggested improvement to the current structure:

{
    "word": "work",
    "phonetic": [
        "wəːk"
    ],
    "meanings": [{
        "partOfSpeech": "noun",
        "definitions": [
            {
                "definition": "activity involving mental or physical effort done in order to achieve a purpose or result.",
                "example": "he was tired after a day's work in the fields",
                "synonyms": [
                    "labour",
                    "toil",
                    "exertion",
                    "effort",
                    "slog",
                    "drudgery",
                    "the sweat of one's brow"
                ]
            },
            {
                "definition": "a task or tasks to be undertaken.",
                "example": "they made sure the work was progressing smoothly",
                "synonyms": [
                    "tasks",
                    "jobs",
                    "duties",
                    "assignments",
                    "commissions",
                    "projects"
                ]
            }
        ]
    }, {
        "partOfSpeech": "verb",
        "definitions": [
            {
                "definition": "be engaged in physical or mental activity in order to achieve a result; do work.",
                "example": "an engineer who was working on a design for a more efficient wing",
                "synonyms": [
                    "toil",
                    "labour",
                    "exert oneself",
                    "slave (away)",
                    "plod away"
                ]
            },
            {
                "definition": "(of a machine or system) function, especially properly or effectively.",
                "example": "his phone doesn't work unless he goes to a high point",
                "synonyms": [
                    "function",
                    "go",
                    "run",
                    "operate",
                    "perform"
                ]
            }
        ]
    }]
}

Regrettably, I'm going to use the Oxford Dictionaries API.

@simpleshadow simpleshadow changed the title Response Structure Poor JSON response structure Mar 11, 2019
@meetDeveloper
Copy link
Owner

@simpleshadow I will look into this, this is my first API, so I did not knew about such things, I will look into it, and I will make changes, because this would be a breaking change, probably, I will ask you to pass version in query param, and based on version show either this structure or old one.

@kovinet
Copy link

kovinet commented Mar 16, 2019

Proposed JSON structure really is more logical, in Turkish, for example, I get 'ünlem' as key in json sometimes and it is not practical to have to iterate trough to be able to access values instead of accessing directly by a known and fixed key.
But as you proposed, it would be nice if current version would keep same structure and the new one would be only for new version of API because it is breaking change.

@emert117
Copy link

Some of the "meaning" types that I found:

determiner
abbreviation
noun
verb
adjective
preposition
adverb
preposition & adverb
exclamation
predeterminer, determiner, & pronoun
conjunction
crossReference
transitive verb
determiner & pronoun
pronoun
crossReference
auxiliary verb
preposition, conjunction, & adverb
proper noun
cardinal number
modal verb
plural noun
conjunction & adverb
determiner, pronoun, & adjective
ordinal number
adverb & adjective
adjective & pronoun
preposition & conjunction
determiner, predeterminer, & pronoun
adjective & determiner
conjunction & preposition
relative pronoun & determiner
interrogative adverb
interrogative pronoun & determiner
possessive determiner & pronoun

@meetDeveloper
Copy link
Owner

@simpleshadow @kovinet I have implemented version 1 of api to have this structure, currently I have not implemented for english language, for other languages you can access the version by sending v=1 in query params, can you use it and tell me if that is what you were looking to?

@ghost ghost mentioned this issue Jan 14, 2020
@hexdecimal16
Copy link

I am also experiencing same problem. The meanings data in JSON response is hard to iterate over. Please make meanings return JSONObjects instead of JSONArrays then the problem would be solved.

@meetDeveloper
Copy link
Owner

@hexdecimal16 I will implement that feature this weekend.

@hexdecimal16
Copy link

@meetDeveloper Thanks...

@hexdecimal16
Copy link

@meetDeveloper hey man did you looked it?

@meetDeveloper
Copy link
Owner

meetDeveloper commented Mar 30, 2020

Yeah will push fix today or by tomorrow at most.

@meetDeveloper
Copy link
Owner

@hexdecimal16 I have done it, you can change v1 to v2 and it will work. Example: https://api.dictionaryapi.dev/api/v2/entries/en/hello

@meetDeveloper
Copy link
Owner

Sorry for the delay, life got me.

@meetDeveloper
Copy link
Owner

@simpleshadow Can you verify once this is how you wanted?

@hexdecimal16
Copy link

@meetDeveloper Yah now it's fine. Thanks!

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

No branches or pull requests

5 participants