-
-
Notifications
You must be signed in to change notification settings - Fork 7k
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
🐞 it seems that there is a bug ? #513
Comments
In the first sample, you are declaring a single object The second sample works because you are declaring an array of objects, and they have their own "space" (Delimited by the For instance:
There's a collision on the Using an array:
There's a collision in the property If you want to validate your code, I recommend using some online linter like this one. More info on the subject: http://stackoverflow.com/questions/21832701/does-json-syntax-allow-duplicate-keys-in-an-object |
😄 Thanks for your time! 👍This is a very good explanation! However, I still have some confused, could you give more explain?
{
"profile": {
"name1": "typicode1",
"name2": "typicode2",
"name3": "typicode3"
},
"employess": [
{
"id": 0,
"firstName": "Jaiden",
"lastName": "Williamson",
"email": "Kiera.Prosacco70@hotmail.com"
},
{
"id": 1,
"firstName": "Elody",
"lastName": "Leuschke",
"email": "Ena_Beier22@gmail.com"
}
]
} {
"name1": "typicode1",
"name2": "typicode2",
"name3": "typicode3"
} How can I get this result ? {
"name2": "typicode2"
} |
You can use 3 methods to access your object: directly by key, using Querystring or by key/param. Direct access:
Query: Using querystring:
Query: Key/parameter:
Query: To access the object in the querystring, you have to select the first element in the array that it returns. In javascript, it would be I recommend using the third method, as it is easier to read and is widely used (As an example, Github API. [They use the username as the primary key for queries, instead of id. Your profile: here]). JSON-Server implements some of the HTTP verbs, so you can automatically GET/POST/PUT/DELETE values. There are also extra functionalities like filter, paginate, sort... the documentation is on the home page of the project. Just remember that this is a fake service, use this project just as a reference for implementing your REST endpoints with a proper backend later on. |
Thanks a lot, again! |
cara estou com esse json, queria consumir ele na minha outra pagina, vi que consome com require() mas da erro pq tem que ser java puro e estou utilizando api, se puder dar uma força.
} |
🐞
The text was updated successfully, but these errors were encountered: