extract data from a JSON object

I am in possession of the JSON data shown below:

[

{
    "AVG_VALUE" : "2540", 
    "MAX_VALUE" : "2540",
    "SUM_VALUE" : "2540",
    "MIN_VALUE" : "2540",
    "METRICID" : "100248060212",
    "START" : "1449216120000",
    "STARTTIME" : "09:02"
}
,
{
    "AVG_VALUE" : "2624", 
    "MAX_VALUE" : "2708",
    "SUM_VALUE" : "5248",
    "MIN_VALUE" : "2540",
    "METRICID" : "100248060219",
    "START" : "1449216120000",
    "STARTTIME" : "09:02"
}
]

However, I am uncertain on how to extract the values from it. Currently, I am utilizing the dojo toolkit and have generated my file using the following code snippet:

var stream = dojo.xhrGet({
            url : self.jsonFile,
            content : {
                startTime : 1449136661084,
                endTime :   1449482261084,
                interValMillis : (interval * 1000),
                metricid : 100248060219
            },
            handleAs : "json",
            sync : true,
            load : function(response, ioArgs) {
                self.data = response;
                self._metricIds = _metricIds;
                self._params = _params;
                self.convertData(self);
                console.log("ok:"+response);
                data = response;
            }
        });

After executing the above code, all the values now reside in my 'response' variable. However, I am unsure how to access it to retrieve, for example, the value of the first AVG_VALUE field.

Answer №1

When working with JSON data, it is stored in object arrays. Therefore, you will need to iterate through them in order to access the values contained inside.

for (var i = 0; i < response.length; i++) {
var jsonData = response[i];
jsonData['AVG_VALUE'] 
}

The code above retrieves all values corresponding to the variable AVG_VALUE. If you only require the first value, then you can use:

 var jsonData = response;
jsonData[0]['AVG_VALUE']

Answer №2

Feedback is represented as an object array. You have the option to access it using response[0]['AVG_VALUE'] or response[0].AVG_VALUE.

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

What is the best way to eliminate the comma at the end of the final array

<% for(var i=0; i < 10; i++) { %> <a href="#"><%= related[i] %></a><% if(i !== 9) { %>, <% } %> <% } %> Displayed above is some code that includes a loop to display related items. The goal is to remove the comm ...

struggling to update an array with user inputs on my to-do list app

I'm currently in the process of creating a small to-do list with some specific functionality. I want each text input (or a copy of it) to be added to an empty string, ensuring that the original input remains unchanged. The goal is to have a function t ...

What is the best method for emulating ui-sref from an ng-swipe event?

State Change Triggered by Swipe: I am trying to change the state of my application using a swipe event. I have looked at the ui-router documentation which suggests using $state.go(), but I'm not sure if this is the best approach? QUESTION: How can I ...

Using Angular 2 to Create Nested ngFor Loops

I'm facing an issue that I can't seem to resolve. I attempted to use *ngFor in my code, but it seems that I am making a mistake with nested ngFor loops. To illustrate what I need to achieve, I ended up writing some messy code just to show the str ...

We could not locate the requested resource with a DELETE request using the fetch JSON method

Currently, I am in the process of developing a webpage that utilizes JSON API REST alongside XAMPP with an Apache server. Up until now, everything has been working smoothly as I have been utilizing the DELETE method successfully. However, I seem to have hi ...

User has logged out, triggering the browser tab to close automatically

Is it possible to automatically log out the user when all browser tabs are closed? How can I obtain a unique ID for each browser tab in order to store it in local storage upon opening and remove it upon closing? Here is what I have attempted: I am utiliz ...

What is the best way to convert a recordset to an array using React?

I'm attempting to create an array by retrieving data from a SQL recordset: +------------+------------+------------+ | start_type | field_name | start_text | +------------+------------+------------+ | 0 | Field1 | some text. | +----------- ...

React JS Bootstrap Dropdown Troubleshooting

I'm facing a challenge in my React.js project while trying to implement a filter. The issue is that the list appears when I click on the button, but it doesn't disappear on the second click or if I click outside the list. Initially, I imported t ...

Having trouble using $.post in jQuery AJAX with the .click() method?

I am experiencing some issues with my ajax request. It appears that the $.post method is not functioning as expected, as no request is being sent. There is also no information showing up in Firebug. Interestingly, I can make this code work: $('.c ...

Create a function within jQuery that triggers when an option in a select field is chosen

As I edit a podcast, I have encountered a situation where an option is being selected through PHP code. Now, I am looking to implement jQuery functionality for when the option is selected from the select field. I have searched through various questions an ...

Combine two JavaScript values dynamically and assign them to the corresponding child in Play Scala

I am trying to merge two sets of data into a specific structure. The first set 'x' contains information about sports, states, and companies in JSON format. The second set 'y' includes labels and IDs related to the same categories. I nee ...

How can global variables be effectively shared and edited between two separate runs of JavaScript nodes?

The primary function contained in main.js is as follows: var nLastPingTime = 0, nLastPingNumber = 0; module.exports = { compareData: function(nPingTime, nLastPingNumber){ nLastPingTime = nPingTime; nLastPingNumber = nLastPi ...

Storing JSON data in LocalStorage or within the App on Ionic 2

I am currently in the process of developing a mobile app for both IOS and Android platforms. The app will feature a list of objects including images, names, etc., which are stored on a backend server powered by node.js. My goal is to allow users of the ap ...

"Unexpected discrepancy: Bootstrap Glyphicon fails to appear on webpage, however, is visible

I am having some trouble getting the glyphicon to display properly in my side nav. The arrow head should rotate down, which is a pretty standard feature. Here is the link to the page: The glyphicon should be visible on the "Nicky's Folders" top leve ...

Is there a way to track when the Angular DTOptionsBuilder ajax call is complete and trigger a callback function?

Working with angular datatables, I have the following code: beforeSend:</p> success callback causes the table on the page not to populate with the data. How can I implement a callback that triggers once the ajax is done without interfering with the ...

I'm caught in a never-ending cycle as I navigate through sending information to my Python API and subsequently utilizing that information in the Next.js application to execute the Python script

I am encountering an issue with the response message, getting "Error sending data." The problem seems to arise when trying to retrieve data in server.py that is already specified in the code. For example, instead of using "msg_user", I should use ...

Setting the default value for drop-down menus in jqGrid form editing

I have a data object with 3 attributes: ID Abbreviation Description In my jqGrid setup, I've configured the grid to display the Abbreviation. During editing (using the Form Edit feature), I populate the dropdown list with ID/Description pairs usin ...

JavaScript function to copy the first row of a table to the clipboard

I am new to JavaScript and I'm facing an issue with copying cells in a table. I have successfully created a table based on my MySQL database, but when I try to copy a cell using the copy button, only the first cell gets copied. I understand that I nee ...

What is causing the difficulty in accessing the 'query' feature within the API, and why is the question bank failing to display?

Just wanted to mention that I am still learning about class based components, setState, and other concepts in async JS like axios. Below is a very basic example of what I can currently do. This is App.js: import Questions from './components/Ques ...

Tips for pressing the enter key to submit when faced with two buttons

I am developing a form with two input fields and their respective submit buttons. I want users to be able to enter text into either field, hit the Enter key, and have it trigger the same action as clicking the submit button. Currently, pressing Enter after ...