Unable to access object key data from JSON-SERVER

I am currently attempting to send a GET request to json-server in order to retrieve data from a nested object. However, the response I am receiving is empty instead of containing the desired data key.

After thoroughly reviewing the documentation, I could not find any information specific to the structure of the database that I am using.

My intention is to filter the model array but unfortunately, I am unable to access the model data.

Here is an excerpt from my db.json file:

  {
      "data": {
          "model": 
            [
               {
                  "name": "BERLINGO",
                  "manufacturerName": "CITREON",
                  "id": 1
              },
              {
                  "name": "C3",
                  "manufacturerName": "CITREON",
                  "id": 2
              }
          ]
      }
  }

When sending a GET request to /data, the response I receive is as follows:

{
  "model": [
    {
      "name": "BERLINGO",
      "manufacturerName": "CITREON",
      "id": 1
    },
    {
      "name": "C3",
      "manufacturerName": "CITREON",
      "id": 2
    }
  ]
}

However, when making a GET call to /data/model, I am only receiving an empty object.

{}

Answer №1

Regrettably, the "nested value" syntax is not supported by json-server. You are able to GET /data, but unable to access GET /data/model or GET /data.model. Your only option is to retrieve the entire /data object and then access the model field within it.

This matter has been previously addressed in json-server's GitHub repository. Based on an earlier discussion, it appears that the creator of json-server (@typicode) does not plan to add this feature.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Angular (2/4) application utilizing custom-named routing within a single page architecture

I'm currently working on an Angular application that consists of a login component and a home component which serves as the main handler for the entire single page application. Additionally, I have three more components named users, each with function ...

combine multiple select options values in a single function using jQuery

My HTML code includes two select options for users to choose the origin and destination cities. I need to calculate the cost of travel between these cities. How can I compare the selected options using jQuery? </head> <body> <div> ...

My pure JS component is not being recognized by ASP.NET Core when integrated with Vue.js

I decided to try writing a simple component in "ASP.NET Core with Vue.js" template using pure JS instead of Typescript. However, I encountered an issue where my port does not seem to work properly. What could be causing this problem? in ./ClientApp/compon ...

How to seamlessly upload an image in PHP without the need to refresh the page

Can anyone provide guidance on how to upload an image without having to refresh the page? I have been searching for solutions but haven't found a suitable one yet. ...

Transferring array data between two distinct click actions

Is there a way to transfer values between click events in jQuery? For example, on the first click event I want to add or remove values from an array based on whether a checkbox is checked. Then, on the second click I would like to iterate through all the ...

Anticipated that the absence of a value would match the presence of an Object

Struggling with running AngularJS unit tests for $resource using Jasmine v2.0 and Karma v0.13, I managed to convert custom actions to newer syntax successfully. However, a specific type of test is giving me trouble, which I suspect is related to $httpBacke ...

Customize the shadow array values in Material UI themes by utilizing the createMuiTheme function to override default

Currently, I have a customized theme for my toolkit where I am utilizing createMuiTheme to override various properties like palette, fonts, etc. One particular challenge I am facing is in minimizing the shadow array within the theme object which contains 2 ...

Jquery cascading menu

I'm currently experiencing difficulties in creating dropdown menus using jquery and css. Below is my HTML code: <nav class="topNav"> <ul> <li> <a href="#menu" class="menu-toggle"><img src ...

Show blank value if there are no search results, along with an additional menu option

I am currently working on a Typeahead feature with a customized menu using the renderMenu method. In this setup, I have added 2 custom menu items at the bottom - one divider and a button. An issue arises when there are no search results. If I do not inclu ...

What is the best way to incorporate a condition within react material-ui components?

Currently I am constructing a generic data table using react and material-ui. My programming background is in c# and java, as well as some early experience with javascript. However, I am encountering syntax issues within reactjs. Here is the particular pi ...

Sending dynamic boolean model property via AJAX dynamically

I am facing an issue while passing a property from my model to an AJAX form. The boolean value is resolving as "true/false" and causing problems in the process. $.ajax({ url: '/Projects/SearchTable2', type: "GET", data: { sub ...

In Vue(tify), transitions require children to have keys, but in this case, there are no tags present as children

Trying to implement a transition on a list using Vue and Vuetify, but encountering the error message vue.runtime.esm.js?2b0e:619 [Vue warn]: <transition-group> children must be keyed: <v-card> I attempted the Vuetify approach <v-fade-transi ...

When the HTML and PHP code keeps running, the JavaScript text on the page updates itself

I was experimenting with threading in different languages like Java, PHP, and JavaScript. I am aware that JavaScript is single-threaded and PHP lacks robust threading capabilities. Below is the code snippet I have been working on: <body> <p id= ...

Inject parameters into the templateUrl property of an Angular component

In this scenario, my component object is structured as follows: var options = { bindings: { title: '<', rows: '<' }, controller: registers, templateUrl: function ($element, $attrs) { return ...

When exporting data from Datatable to Excel, decimal values including the % symbol may experience rounding issues

I am facing an issue when trying to export a Datatable to an excel sheet. The column in the Datatable contains decimal values with a % symbol. However, after exporting, the decimal values are being rounded off. I need the decimal values along with the % sy ...

Set up the Redisson client to utilize two codecs at the same time for optimal performance

Our team utilizes Redisson and is currently testing out the Snappy compression codec in order to decrease Redis storage. We typically use JSON code for custom data serialization. In our efforts to prepare for rollbacks on production, I am investigating t ...

PHP code that involves encoding an array containing multiple arrays that have been previously encoded using json_encode

Something strange is happening to me when using the json_encode() function. When I apply it to a single array, the output is valid JSON. However, if I try something like this: $ar['key'] = "name"; $array[] = json_encode($ar); $json = json_encode ...

jQuery Animation Issue: SlideDown Effect Not Working as Expected

I'm feeling quite confused about this situation. I've been attempting to utilize the slideDown function in jQuery, but when I click on the 'information' div, it just jumps instead of animating smoothly. I suspect that one of the cause ...

Is it possible to save or write a text file in the VueJs renderer process without the need to open the dialog box?

Currently, I am working on a project using VueJs + electron, where I need to save a text file to the user's PC without any prompt or dialog box popping up. I am aware of how to do this using require('fs'), but unfortunately fs does not work ...

Using Ramda, learn how to transform a flat list into a hierarchical one

Looking to transform the given list into a hierarchical structure with nested children fields. The 'parentId' attribute has been omitted for clarity, as it will be used in the transformation process using Ramda's immutable behavior. const x ...