What is the best method for extracting a nested json value without a key?

Is there a way to retrieve a specific value from a nested JSON object that does not have a key?

I'm attempting to access the "2019-03-19T22:57:47.972Z" value within this JSON structure:

var json = {"metaData":[{"name":"ACTION_NAME"},{"name":"SENT_RECV_TIME"}],"rows":[["SI_OA_CTPParameters","2019-03-20T06:20:45.704Z"],["SI_OA_CTPParameters","2019-03-21T06:04:08.313Z"],["SI_OA_CTPParameters","2019-03-21T06:01:14.412Z"],["SI_OA_CTPParameters","2019-03-20T06:59:54.875Z"],["SI_OA_CTPParameters","2019-03-20T20:32:50.975Z"],["SI_OA_CloudDataAddress","2019-03-19T22:57:47.972Z"],["SI_OA_CloudDataAddress","2019-03-19T22:56:52.115Z"],["SI_OA_CloudDataAddress","2019-03-19T22:54:28.196Z"] ......

Currently, I am only able to extract json.rows[0], which gives me:

["SI_OA_CTPParameters","2019-03-21T06:04:08.313Z"]

I tried using json.rows[0].[1] but that didn't work.

All I need is the second value "2019-03-21T06:04:08.313Z", how can I access it?

Answer №1

To retrieve nested values from the JSON object, use json.rows[0][1] in your code like so:

var json = {"metaData":[{"name":"ACTION_NAME"},{"name":"SENT_RECV_TIME"}],"rows":[["SI_OA_CTPParameters","2019-03-20T06:20:45.704Z"],["SI_OA_CTPParameters","2019-03-21T06:04:08.313Z"],["SI_OA_CTPParameters","2019-03-21T06:01:14.412Z"],["SI_OA_CTPParameters","2019-03-20T06:59:54.875Z"],["SI_OA_CTPParameters","2019-03-20T20:32:50.975Z"],["SI_OA_CloudDataAddress","2019-03-19T22:57:47.972Z"],["SI_OA_CloudDataAddress","2019-03-19T22:56:52.115Z"],["SI_OA_CloudDataAddress","2019-03-19T22:54:28.196Z"]}};

console.log(json.rows[0][1]);

Answer №2

json.rows[0] retrieves an array, which we will refer to as 'a'. Individual elements of an array can be accessed by their index, like so: a[1] will provide the element you are looking for.

Although it may not be convenient to rename the array, you can simply reinsert the original statement within 'a'; therefore, json.rows[0][1] will also work effectively.

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 sidebar icons appearing vertically instead of in a row

Greetings! I've been struggling for hours to display a sidenav using Angular 2, with links listed as rows. Here is what my current setup looks like: https://i.sstatic.net/fmmAR.jpg Here is the code I've been working on: <md-sidenav-containe ...

Combining the first and last sets of data in Java to generate a fresh JSON object

I am facing a challenge with 2 queries that are returning the same object for earliest and latest datasets. For example: earliestDataset = [ {'id' : 123, 'highlights': 2, 'created_date': 2024-01-01, 'saves':5, &apos ...

utilizing PhoneGap for transforming a website into a mobile application

My website is already built and fully functional using ajax, jquery, html, and php. When converting it over to PhoneGap, I'm wondering if I need to create all new php files to attach to the PhoneGap server, or if I can just use the existing files from ...

"Exploring the World Wide Web with JavaScript and Ajax in Internet

Is there a way to include a Javascript snippet at the end of some ajax content? It seems to be functioning properly in Firefox, but when I try it in Internet Explorer, the script is printed out without being executed. <script type="text/javascript"&g ...

Blog Writer: Picture quality compromised when adjusting size

Issue with blurry images after resizing. The problem is noticeable in the three main images located under the Header section. To preview the blog, click on this link: Click Here Your assistance in solving this issue would be greatly appreciated. Thank yo ...

React.js - Looping through bootstrap cards

I'm completely new to React.js and I have a specific challenge I need help with. I want to display a grid of images as cards, with three cards in each row and a space between each row. I have the following card Bootstrap code: function App() { re ...

Troubleshooting Django user login Ajax problem with Bootstrap 3.x modal

After submitting the modal form, an AJAX request is made to pass the username and password to a view and retrieve JSON information to update the form. I have confirmed that the JsonResponse(rsdic) has been executed on the server side and the client receive ...

The slice() function is displaying the correct output in the console, but the string is not being updated in the <td>

I am facing an issue where the console displays the expected substring, but the original string in the HTML remains unchanged. The goal is to truncate any long text within each table <td>. It's important to note that I'm specifically avoi ...

Ways to verify if JSON response is null using jquery

$.getJSON(url, function(json) { var output = ''; $.each(json, function(i,d) { if(d.DESCRIPTION == 'null'){ console.log("Its empty"); } var description = d.DESCRIPTION; output += '<tr><td>&apo ...

What is the most efficient way to transfer an object between two functions in AngularJS?

As a beginner in AngularJS and Javascript, I recently attempted to pass an object from one function to another. Here is the HTML Code: <div ng-click="getValueFromHtml(userObj)">send Object </div> This is the Controller Code: $scope.getValueFr ...

Storing blank information into a Mongodb database with Node.js and HTML

Can someone please assist me with solving this problem? const express=require("express"); const app=express(); const bodyparser=require("body-parser"); const cors=require("cors"); const mongoose=require("mongoose"); ...

Simple JavaScript Calculator

I'm currently working on a basic JavaScript Mortgage calculator, but I'm facing some challenges. I haven't implemented the math yet and I'm struggling to display the final sum (x + y + z) below the form after submission. The reset form ...

Encountering Axios errors while executing API calls at a high frequency

Recently, I have been facing some challenges with making API calls from localhost using axios in a loop. While it works smoothly at times, most often I encounter errors like: cause: Error: connect ECONNREFUSED ::1:8000 at TCPConnectWrap.afterConnect ...

Positioning an Element on a Web Page in Real-Time

Trying to implement an Emoji picker in my React application, I have two toggle buttons on the page to show the picker. I want it to appear where the Toggle button is clicked - whether at the top or bottom of the page. The challenge is to ensure that the pi ...

Click the button in Javascript to add new content

I am currently experimenting with JavaScript to dynamically add new content upon clicking a button. Although I have successfully implemented the JavaScript code to work when the button is clicked once, I would like it to produce a new 'hello world&ap ...

Programmatically conceal a grid panel column in ExtJS 5

Is there a way to conceal a column in an ExtJs 5 grid panel as soon as the associated store has finished loading? ...

What is the process of creating a global variable in Node.js?

My task involves calling an API that will return a JSON object stored in a variable. I need to print part of this JSON object on the console. However, I am facing an issue where I can't load the data to the console outside of the request{} loop. How c ...

The video is not displaying on the webpage when connected locally, but it appears when the source is a URL

Recently, while practicing some basic tasks on a cloud IDE called Goorm, I encountered an issue with displaying a video on a simple webpage. The EJS file and the video were located in the same folder, but when I set the src attribute of the video tag to "m ...

I need to send both a HttpStatusCode and a Json Object from an MVC Controller to a JavaScript client

I attempted the method below, and while it works fine on my local machine, when running on the testing server it only returns a BadRequest without the expected JSON object in the response: var customObject = new { Message="", Parameters="a1,a2"}; Resp ...

Purge ajax result upon completion of server operation

I'm currently working with an AJAX code that takes input from a radio form. The server code, upon satisfying a specific if() condition, redirects to another page on my site, such as dashboard.php! However, upon redirection, I am still seeing the rad ...