How can you extract a property value from a nested object using JSON parsing?

Attempting to parse a property within nested objects and an array using JSON.parse(nodeInfluxSeries). Here's the structure:

 Array [
  Object {
    "id": 1,
    "properties": Object {
      "nodeInfluxSeries": "[{\"database\": \"boba\", \"fields\": [], \"measurement\": \"boba\", \"retentionPolicy\": \"boba\", \"tags\": {\"nodeId\": \"boba\"}}]",
      "series": "",
      "version": "",
    },
    "userRights": Object {
      "monitorManagement": true,
      "propertyEdit": Object {},
    },
  },
]

Attempted the following, but it adds a new property to the first object.
note: random refers to the array

    random.map(r => {
      return {
        ...r,
        nodeInfluxSeries: JSON.parse(c.properties.nodeInfluxSeries),
      };
    })

Answer №1

To properly handle the data, make sure to nest the JSON.parse() method within the properties property of the outcome.

random.map(r => {
  return {
    ...r,
    properties: {
      ...r.properties,
      nodeInfluxSeries: JSON.parse(r.properties.nodeInfluxSeries)
    }
  };
})

If you prefer, you can directly update the property instead of reconstructing all the objects:

random.forEach(r => r.properties.nodeInfluxSeries = JSON.parse(r.properties.nodeInfluxSeries));

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

Utilize an array with dynamic referencing

I am attempting to reference a single index out of 30 different indices based on the user's actions, and then utilize ng-repeat to iterate through each item in the index. Controller: $scope.meals = [ { title: 'Abs', url:"#/app/mworkout ...

What is the process for incorporating name columns into a pre-existing numpy array?

I'm currently attempting to assign column names to an existing numpy array. After researching in this post, I discovered that using .dtype.names allows you to set the column names for a numpy array. However, when I try to name the columns in an exis ...

Organize array elements based on common characteristics in Group C

Consider the following array: [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16] Is it feasible to organize the array elements like this: [0 6 12, 1 7 13, 2 8 14, 3 9 15, 4 10 16] Each new element in the sequence consists of three previous elements in that ord ...

Unlock the potential of ng-for to dynamically generate input boxes and checkboxes!

In this Angular application, my requirement is to repeat the elements inside a div based on the number entered in an input box (record.accountRoles). <!-- Input Box --> <div class="form-group"> <label for="name">Enter the number of a ...

"Can you explain the concept of an undefined id in an AJAX request

Within my mongodb database, I have two Tables: GstState Store While working on my Store form, I encountered an issue where the JSON response was returning an undefined id when trying to select a state based on country via an ajax call to fetch GstStates ...

Require modification of JSON values in React Promise code

Looking to modify the data returned from a promise and wrap a link around one of the fields. Here is the React code: this.state = { medications: [], } queryMeds().then((response) => { this.setState({medications: response}); }); The response c ...

Changing the value in a textbox by altering a select option involves adjusting the input based on the selected

Is there a way to update the input value when a new option is chosen from a select dropdown menu? Click here to view an image. The goal is to have a different number of image upload fields based on the selected ad package (e.g., free package has 0 images ...

Issue with displaying Images on Datatables using Javascript

I have been scouring the depths of the Internet. Everything was running smoothly, I was handling image uploads and retrievals with NodeJs to MongoDB using the schema below: image: { data: fs.readFileSync(path.join(__dirname, '/public/uploads/&apos ...

What does arguments[0] represent when using the execute_script() method with a WebDriver instance in Selenium using Python?

I'm currently in the process of crawling specific pages that catch my interest. In order to do so, I need to eliminate a particular attribute from an HTML element - specifically, the 'style' attribute is what I aim to remove. To achieve this ...

"Exploring the process of retrieving data from a request in Node.js with the help of the Express

I'm encountering some issues with integrating a "login" form into my Node.js script. While I can get it to work using a static HTML page, utilizing a dynamic ".ejs" page is causing trouble as my form fields are showing up as "undefined". var helmet = ...

Notification window when the page is being loaded

My goal is to have a module or alert box display when my website is opened, and then disappear after 5 minutes. To see an example of what I'm looking for, take a look at this website: On that website, there is a facebook.com box that automatically d ...

A step-by-step guide on creating a chainable command in Cypress

Imagine having a variable called username. Now, consider a chainable function that needs to verify whether the username is empty or not. Original Method: if(username !== "") { cy.get('#username').type(username) } Expected Outcome: ...

Automatically generate nested object properties in VueJS for streamlining code structure

Understanding the Issue I have created a custom system to monitor specific "store" properties from a JSON in a NoSQL database. The structure is fairly straightforward, with nested objects that are necessary for various reasons. The data format resembles ...

"Exploring the Power of Logarithmic Slider with Vue and Quasar

I'm currently working on a project utilizing Vue 2 and Quasar 1, where I am attempting to develop a logarithmic slider. Initially, I managed to create a basic example using a native input slider in this code pen: https://codepen.io/tonycarpenter/pen/Z ...

Issues with Java ArrayList.toArray function - outputting a certain type of reference

I am currently developing a software that requires pulling data from a database and presenting it in a graphical table format. I am facing an issue while trying to convert a 2D ArrayList into a 2D array. For some reason, when I convert the list, it seems t ...

Unable to execute AJAX POST request

https://i.stack.imgur.com/JqG7c.pngI have a JSON dataset like the one below: [ { "Password": "tedd", "Username": "john", "status": true } ] I need to consume this data using a POST method <label for="Username">Username:</label& ...

Eliminate objects from a structured array

Currently, I am working on creating a TCP server chatroom using C and utilizing poll to manage multiple clients. The process involves users registering with a username and password before logging in. Once logged in, I aim to include them in a struct array. ...

reinitialize function post-ajax request

I am currently in the process of rewriting a script that manipulates data attributes to rebuild a block. The original script worked fine, but now I need to implement AJAX functionality. Here is my updated script: (function($){ jQuery.fn.someItem = functio ...

Challenges related to streaming processes and uploading to S3 cloud storage

Encountering difficulties with a zero byte stream. Currently, I am resizing an image and sending it as a stream to S3. Initially, when I connect the output to the response, it displays properly. // To retrieve the file remotely var request = http.get(&apo ...

Unable to update the information within a DIV using Python Django, as well as the webpage following a jQuery action

Exploring new ideas through the lens of two variables in an HTML template, messages and users, a series of buttons trigger a jQuery function upon being clicked. This function sends a post request to a Django server, which then returns an update to the mess ...