How do I call a multiple layer deep Object or a Value of a JSON database?

Issue

I created a Json Server Database like this:

"Time":
  [
    {
     "id":1,
     "name":
     [
      {
       "id":1,
       "checkin":
       [
        {
         "id":1,
         "date":"123",
         "time":"123"
        },
        {
         "id":2,
         "date":"123",
         "time":"123"
        }
       ]
      },
      {
       "id":2,
       "checkout":
       [
        {
         "id":1,
         "date":"123",
         "time":"123"
        }
       ]
      }
     ]
    }
   ]

I don’t want to get the entire Database and go through it. I just want to tell the Database where exactly my Object is and have it returned.

How would I call the call for example the first Check-in Object?

I use the Angular HttpClient like this:

this.http.get(endpoint, JSON.stringify(time), this.httpOptions))

So I need the Exact Endpoint in a format like: endpoint/id/id or similar

I imagined it like this: endpoint/time/1/1
With output:

[
 {
  "id":1,
  "date":"123",
  "time":"123"
 }
]

If this is not possible please tell me anyways.

PS: The question from this thread is essentially the same as mine. Also the JSON documentation doesn’t real help either, it just says you need custom routes for multilayer JSON strings but not how to implement these routes.

Solution

Apparently a request like I wanted to call is still not possible. The only way to come close is to fake it with custom Routes and flattening the JSON structure like in this old thread.

Answered By – compuGreen

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published