Choosing specific information from a deeply nested JSON structure

I am currently dealing with a multi-level JSON object that includes an array of 143 other objects. When I run console.log(obj) on this object, the following output is displayed:

0: Object
  ActFTEs: 0.00
  Actual: 11111
  Bud_Month: "October"
  FY_CD: 2013
  Mission_Name: "RST"
__proto__: Object
1: Object
  ActFTEs: 0.00
  Actual: 10000
  Bud_Month: "FY Total"
  FY_CD: 2013
  Mission_Name: "RST"

and so on for all 143 objects. However, the name/value pair Mission_Name:"RST" only appears in the first n objects.

For example, object 43 looks like this:

43: Object
   ActFTEs: 0.00
   Actual: 10000
   Bud_Month: "FY Total"
   FY_CD: 2013
   Mission_Name: "VAO"

I have created a function to filter out "Bud_Month" values based on the existence of Mission_Name:"RST", but it seems to be returning all 143 values instead of just those associated with Mission_Name:"RST". Here is the function:

function get_dataArray() {
 var arr = [];
 var i= 0;
 for (i=0;i<jsonobj.row.length;i++) {   
    if (jsonobj.row[i][name]="RST") {
         arr[i] = jsonobj.row[i]["Bud_Month"];
    }    
 } 
 console.log(arr);
 return arr;
}

When running this function, the output consists of all 143 "Bud_Month" values as follows:

["October", "FY Total", "December", "January", "February", "March", "April", "May", "June", "July", "August", "September", "FY Total", "October", "November", and so on...]

If anyone has any suggestions on how to retrieve only the "Bud_Month" values from objects that contain the name/value pair of Mission_Name:"RST", I would greatly appreciate it!

Answer №1

if (jsonobj.row[i][name]="HST") {
     arr[i] = jsonobj.row[i]["Bud_Month"];
}   

It is recommended to change to:

if (jsonobj.row[i][name]=="RST") {
     arr[i] = jsonobj.row[i]["Bud_Month"];
}   

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

Modification of a CSS element

The CSS I am working with looks like this: .cls .imageX { float:left; } .cls .imageY { float:right; } It is currently being used on a page in this way: <div class="cls"> <a href="" class="imageX"><img src="left.png"/></a> &l ...

method for sorting labels in Select element in ReactJS

Hey there, I'm facing an issue with the code snippet available here. I would really appreciate it if you could assist me in resolving this problem. This is the code: import React from "react"; import { Select } from "antd" ...

Ensure that the placeholder remains visible as you type in the input field

Is there a way to implement an input text field in React with the placeholder "DD-MM-YYYY," that partially disappears as I start typing? For example, when I type "02-," only "-MM-YYYY" should remain visible as part of the placeholder. ...

Generating a hierarchical JSON structure using Pandas for an organizational chart

I am working on transforming a hierarchical DataFrame in Python 3.5 into a nested JSON object for use in JavaScript to display an Org Chart. I am aiming to achieve the structure outlined in the response provided in this question: Organization chart - tree, ...

Generating a JSON string directly from the results of a database query

I am attempting to generate a JSON object based on the results of a database query. Here is an example of what I am trying to achieve: json_obj= { '1': 'test_1', '2': 'test_2', &apos ...

Unable to link name with the corresponding latitude and longitude information

: I have a page that displays 15 LI items and I'm struggling to convert the complex nested HTML data into a simple JSON object containing the name, latitude, and longitude. Here's an example of how a single record should look: {name: "Pied a T ...

Refactoring the headline: "Transforming a column of JSONs within a Pandas DataFrame into informative rows based on the 'id' field

Consider the given DataFrame as shown below: import pandas as pd df = pd.DataFrame({'id': [1, 2, 3], 'json_col': [ [{'aa' : 1, 'ab' : 1}, {'aa' : 3, 'ab' : 2, 'ac': 6}], ...

Execute a function once the router-view in the App.vue component has been refreshed following a route alteration triggered by vue-router

Is there a way to trigger a function after the contents in <router-view/> within App.vue have been updated following a route change? I attempted using the updated() lifecycle hook, but the function is not being executed. Interestingly, the function ...

How to retrieve the value from a JSON object when the key is unknown in JavaScript

Here is the JSON file I'm working with: { "status": 200, "msg": "OK", "result": { "files": { "count": 1, "pUnJbKzql0f2": { "name": "How ...

Guidelines for incorporating role-based permissions in a React application

I am developing a MERN application that has various features catering to different roles. I need the ability to display specific data, navigation options, and divs based on the user's role while hiding these elements from others. It is important to no ...

Retrieving Information from JSON Response (C# with Windows Forms)

I'm having a bit of trouble extracting the street, town, and county from the JSON data retrieved using the Google Mapping API based on the postcode input. At the moment, I can successfully store the JSON data in a variable. However, I need help with ...

When attempting to insert a new object in Laravel, the JSON file gets completely replaced

I have a scenario where I need to add a JSON object to an existing JSON file (located in the `storage/app` folder). However, every time I do this, it ends up replacing all the previous data. The code snippet from my controller is as follows: public funct ...

The anchor tag's href attribute isn't working properly when using a single slash, but it works

I'm encountering an issue where my absolute URL is not clickable in an anchor tag as shown below: <a href="/account/login"><Login</a> However, it works with double slashes: <a href="//account/login"><Login</a> B ...

Adding a symbol to a button

My goal is to add an icon to this button using JavaScript: <button id="chat5" onclick="updateChatId('{{ element.pk }}')" class="btn btn-secondary" style="background-color: maroon; border-color: transparent; border-radius: 15px; height: 60px; ...

Ajax response data triggered twice

I'm struggling to understand why my data is being called twice. I attempted to replace 'append', but it's not working. I suspect the issue lies within my controller. Here is my Ajax call: jQuery(document).ready(function($) { $('# ...

Sort the objects in the array based on a specific property

Object A contains the following: [{grade:1},{grade:2},{grade:3}] up to 100th. How can I map the existing data (referred to as Object B) onto them? [ {grade:1,name:'alice',address:{poscode:123},tel:324} {grade:5,name:'wonder',address ...

How to handle the discrepancy between NextJS exporting files with a .html extension, yet in the <Link> component there is no .html specified

I have been working on my NextJS application and I've realized that all the links within it are built using the <Link href="/my-page"><a>My page</a></Link> component. After exporting the app to generate a static site, ...

What are the differences between displaying JSON data on a Flask interface compared to a Django interface

Currently, I am looking for the simplest method to display data on a web interface using either Flask or Django (whichever is easier). I already have some sample JSON objects available. Could anyone provide recommendations on how to achieve this and whic ...

Caution: It is not possible to make updates on a component while inside the function body of another component, specifically in TouchableOpacity

I encountered this issue: Warning: Trying to update a component from within the function body of another component. Any suggestions on how to resolve this? Interestingly, the error disappears when I remove the touchable opacity element. ...

Changing the designated materialUI class

Within the project, I am utilizing this theme: export const theme = createMuiTheme({ ...defaultThemeConfig, overrides: { ...defaultThemeConfig.overrides, MuiListItem: { root: { '&:nth-child(odd)': { backgro ...