Challenges encountered with extracting information from a JSON dataset

When I make an Ajax POST request, the response I receive is structured like this:

{
    "columns": [
        "r"
    ],
    "data": [
        [
            {
                "extensions": {},
                "start": "http://localhost:7474/db/data/node/2762",
                "property": "http://localhost:7474/db/data/relationship/2709/properties/{key}",
                "self": "http://localhost:7474/db/data/relationship/2709",
                "properties": "http://localhost:7474/db/data/relationship/2709/properties",
                "type": "IS_CONNECTED_WITH",
                "end": "http://localhost:7474/db/data/node/2763",
                "metadata": {
                    "id": 2709,
                    "type": "IS_CONNECTED_WITH"
                },
                "data": {
                    "FOC_Type": "IRU",
                    "DuctType": "IRU",
                    "TrenchType": "IRU",
                    "linestringId": "53805"
                }
            }
        ]
    ]
}

The response above appears as a string. My goal is to access specific elements within it such as "FOC_Type":"IRU","DuctType":"IRU","TrenchType":"IRU","linestringId":"53805".

My attempt involves converting the string to JSON using the following code:

  var response = JSON.parse(response);

I then try to extract values in this way:

  var dataEquip = response[Object.keys(response)[Object.keys(response).length - 1]]; 
  var komvosName = dataEquip[0][2];

Despite my efforts, I have not been successful in making it work.

I have resorted to a workaround where I manipulate the string directly without converting it to JSON format. However, this solution is not ideal. If anyone can provide guidance on what I might be doing wrong, I would greatly appreciate it.

Answer №1

Consider trying out this approach:

let responseJSON = JSON.parse(response);
let dataEquip = responseJSON ['data'] // extract the data from json object
let nodeName = dataEquip['TrenchType'];

In essence, a JSON object (responseJSON) functions similar to an associative array.

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

Error occurred within node while attempting to create a directory using mkdirsync

I wrote some code. try{ var Storage = multer.diskStorage({ destination: function (req, file, callback) { fs.mkdirSync('/home/data/' + file.originalname, { recursive: true }, (error) => { ...

Merge two separate mongodb records

Just getting started with javascript / express / mongodb. For my initial project, I am working on a simple task manager where todos are categorized by priority - "high," "mid," or "low." However, I am facing an issue when trying to display different entri ...

What is the purpose of re-checking the user in the passport.deserializeUser function?

After reading multiple articles on how to utilize passport.js, I'm left wondering why user verification is repeated within the passport.deserializeUser function. The code snippet looks like this: passport.deserializeUser((id, done) => { console. ...

The popup is unable to remain in the center of the screen because the background page keeps scrolling back to the top

Whenever I click a button to open a popup window, the page unexpectedly scrolls to the top. It's frustrating because if I'm at the bottom of the page and press the 'submit' button, the popup doesn't display in the center as intende ...

Decode JSON and generate a user-friendly Array

My aim is to extract and organize the JSON data received from an external API into a custom array. However, I am encountering two challenges: I'm struggling to access the value labeled #2 under "Meta Data". If I want to extract the first array n ...

Securely getting a data point from a pathway

Within my Angular project, I recently made the transition from using query string elements in URLs such as: http://www.whatever.com/products?productName=TheMainProduct&id=234234 To a route-based system like this: http://www.whatever.com/products/The ...

Creating standard forms of AnyVal types using Circe

Is it possible to derive Encoder instances for value classes? I am having trouble deriving nested classes using the semiauto mechanism. Consider the following case class structure: { case class Recipient(email: Recipient.Email, name: Recipient.Name) ...

Warning: The Unhandled Promise Rejection arises when an error is thrown within an asynchronous function without a try-catch block

Encountering the following issue in my Node-Express App UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error came about either by throwing inside an async function without a catch block, or rejecting a promise that was not hand ...

Forward users to specific date and time on Everwebinar link

Is there a way to automatically redirect visitors of my custom Everwebinar confirmation page (on my domain) to a specific URL at a set date and time that is included in the confirmation page URL? Here is an example of what the confirmation page URL looks ...

Rendering HTML strings instead of HTML in ReactJS

When I try to display HTML, all I see is strings var ref = firebase.database().ref('raffle/'); ref.on('value', (snapshot) => { var content = ``; var IDwrapper = document.getElementById('raffleFeed'); snapshot.forEac ...

Specifically on Windows XP, Firefox fails to retrieve JSON data

Using jquery .ajax() for sending and receiving data through JSON works smoothly on all browsers, except for "Windows XP" Firefox. The .ajax() function sends data without any errors, and there are no error messages returned from JSON either. I suspect the ...

Issue with Knockout.js: Parsing error in bindings - SyntaxError: Unexpected token `};`

Take a look at this example. I've tried to simplify it as much as possible, but I'm still struggling to figure out where I went wrong. Any help would be greatly appreciated )) P.S Stack Overflow requires code, not just a link to jsfiddle. H ...

Implementing Firestore Read Limitations in a React Application

I have encountered an issue with Firebase billing based on the number of document reads. There is a daily limit of 50k reads per day in Firestore, but when I try to fetch documents in my React app, it triggers a quota exceeded error. FirebaseError: Request ...

Create a unique component in ReactJS with the react-google-maps package to enhance your user interface

I would like to integrate a custom marker component into the map, but I have observed that using react-google-maps/api does not support rendering custom components. To illustrate this, here is an example of the code I used: const CustomMarker = ({ text }) ...

Exploring the connections between Hibernate and AngularJS

I have established a connection between Travelers and Trips in Hibernate: https://i.sstatic.net/YQetP.png To create a new trip for traveler 1, I need to visit the route /frontend/#/trip-creation/1. Here, a form is available: https://i.sstatic.net/BeXnU. ...

Utilize React Dropzone for effortlessly styling elements upon drop action

Currently, I am working on implementing Dropzone in React. My specific requirement is to display a text and a blue border in the center of the Dropzone area when files are dragged onto it (text: "you are inserting files"). This is how my current code look ...

Issue with attaching dynamic events is not functioning as expected

var smartActionsId = ['smartActions1','smartActions5','smartActions10']; for (let i in smartActionsId) { console.log("smartActionsId ="+smartActionsId[i]); $('#' + smartActionsId[i] + ' select').c ...

Tips for distinguishing between elements in React

I am facing an issue with zooming images on mouse hover using CSS. I have a code snippet that works well, but it zooms both images simultaneously. How can I differentiate between mouse movements over different elements in ReactJS? Here is the code: .styl ...

Vue.js transition-group does not apply the *-move class

As I dive into learning Vue, I find myself wondering if I may have overlooked something fundamental or stumbled upon a bug. Despite multiple readings of the documentation at https://v2.vuejs.org/v2/guide/transitions.html#List-Move-Transitions, I still can& ...

Tips for modifying JSON response using a function

When I call the function buildFileTree, I store its response in a constant variable called data. const data = this.buildFileTree(dataObject, 0); The value of dataObject is: const dataObject = JSON.parse(TREE_DATA); And the content of TREE_DATA is: cons ...