-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
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
Is it possible to access nested objects, in the way I have my json formatted? #814
Comments
To access nested object properties, you would access each nested object by its property name, for example: The 123 object was accessed using bracket notation because it is a number and using dot notation would cause an error to throw. Also, it seems that you're missing commas after each name value, so that could be causing some issues |
In OP's example, why doesn't json-server create resources other than for the top level object? For example, why does it not create: |
Yes, definitely helps to use it as REST API in my app. At the moment, such URL/RAPI doesnt work. My JSON looks like this:
via REST API, i cant access productComments object via URL like http://localhost:3000/products/1-/productComments |
Yes, this was why I was expecting to be able to do. Then I could've quickly put together some dummy data to simulate a "real" API. Will need to look elsewhere for now, unfortunately. |
This issue makes json-server unusable for a lot of API designs. Does anyone have a solution, or perhaps another server that allows this? |
you should look at this comment by the author, maybe you'll find it helpful |
I wholly agree with a lot of the comments here. The disallowance of accessing properties on an object - say /api/posts/1/whatever - is almost unbelievable. It makes the json-server basically unusable for developing anything like a real product. There are so many obvious situations in which that would be essential. I honestly can't imagine why the developers would restrict it in the way they have. |
Yes, we cannot use nested objects but for the purpose of testing we can use custom routes and access that data as seperately |
I agree, either the devs are stupid for intentionally imposing this restriction or they naively wrote garbage code that caused it. For anyone looking for a workaround I've been using a python package I found that supports nesting: https://github.com/gera2ld/json-server.py |
…s and modify nested objects
Right now, on my json server, all I can access is the results object. But how can I specifically go into the values object, and pick one of its objects. Like how would I access "123" and its properties? Please help me out.
The text was updated successfully, but these errors were encountered: