Retrieving specific properties from a JSON object and logging them

I am attempting to access JSON Object properties directly and log them using the following function :

loadProcesses(filter?){

this._postService.getAllProcess(filter)
.subscribe(
    res=> {
        this.processListe = res;
       // console.log(this.processListe.)
    }
,null,
() =>{
    console.log("retrieving processes list: " + filter)

});

The variable this.processListe contains a JSON Object, with a format like this:

{"Person": {
   "id": "A256",
   "name": "GET",
   "status": "active",
   "description": "hardworking, openminded",
   ...

If I want to simply print the label on a console log, how can I do it?

Answer №1

Are you in search of a solution similar to this:

function analyzeData(data)
{
   for(var item in data)
   {
      console.log("item: " + item + ", information: " + data[item])
      if(data[item] instanceof Object)
      {
        analyzeData(data[item]);
      }
   }
}

You can easily execute analyzeData(response) within the subscribe function.

Answer №2

Extract the data and retrieve specific attributes.

let data = JSON.parse(inputData);
data.User.name;
//additional logic here

Answer №3

Extract the data in the .subscribe method:

result => this.parseData = result.json();

Answer №4

One effective approach is to define your reply using a colon:

loadProcesses(filter?){

this._postService.getAllProcess(filter)
.subscribe(
    (res: any)=> {
        this.processListe = res;
       // console.log(this.processListe.)
    }
,null,
() =>{
    console.log("retrieving process list" + filter)

});

This method allows you to access any attribute in the response.

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

The Angular subscription gets triggered multiple times

I am currently subscribed to this service: login(): void { if (!this.loginForm.valid) { return; } const { email, password } = this.loginForm.value; this.authService.login(email, password).subscribe((res) => { if (res.ok) ...

"After completing the task, the textview does not get updated in onpost

I am currently working on creating a movie catalogue app and facing an issue with the DetailActivity. The problem arises when I click on the first movie to view its details, then press the back button. Upon clicking on another movie, the app still displays ...

Could someone shed some light on why my code within the useEffect hook in my component is being triggered twice when it shouldn't be?

I'm currently developing a VR Web project using Three.js within a React-Vite-Typescript setup. As I begin this new project, my focus is on coding the initial view. It starts with a black screen displaying a white logo at the center, reminiscent of in ...

Using FormControl Inheritance in Angular 4

My goal is to enhance the functionality of a FormControl by creating a subclass with additional properties. These properties will then be utilized in custom form controls to modify behavior. I attempted to inherit from FormControl (let's call it Stan ...

Locate the index position of an element in one array based on a corresponding element in a

I am seeking a way to determine the index and group that an item belongs to within a parent json group. Is there a method for achieving this? I am willing to modify the json format if necessary. I made an attempt using JSON.stringify(), but it seems to be ...

Vue JSON Response Guide

Inquiry from a beginner. My goal is to display the name of a city using props. When I use {{ props.feed.location }} to fetch: { "latitude": 50.85, "longitude": 4.35, "name": "Brussels, Belgium", "id": 213633143 } However, when I attempt {{ props.feed.l ...

A guide on converting the http response body into a json format in the Go programming language

When I receive a response body, the format of the body is like this: [ { "id":1, "name":"111" }, { "id":2, "name":"222" } ] I am trying to parse ...

How can I create a Python script to generate a call graph and export it as a JSON file?

My challenge is to generate a call graph of code in JSON format. I have explored various Python packages such as coverage, pycallgraph, callgraph, and unittest, but none of them offer the desired JSON output. Pycallgraph came close but fell short of provid ...

Ways to dynamically insert a new row into a table based on user input in a Postman-like reactive table

Is there a way to dynamically insert a row when a single character is entered into an input field in the header tab, similar to how Postman functions? 1) If a user types any single character in the td of the first row, then a new row should be added below ...

Tips on retrieving a dataset from Json when the element is variable

I'm looking for assistance with extracting a specific node from a JSON object in my WebApi. The structure of the JSON object can vary, but I know that it will contain a node with the following properties: "data": { "mop": & ...

The issue of Angular child components rendering before receiving parent data

My current challenge involves a parent component (app.component) making an http request, storing the result in this.stats and then passing it as a prop to the child component (progression.component). The issue arises when my child component tries to render ...

Ways to efficiently group and aggregate data in JavaScript, inspired by LINQ techniques

I'm feeling overwhelmed by this. Could you lend a hand? Consider the following .NET classes: Teacher: public class Teacher { public int Id { get; set; } public string FirstName { get; set; } public string LastName { get; set; } publ ...

Can PHP send back data to AJAX using variables, possibly in an array format?

My goal is to transmit a datastring via AJAX to a PHP page, receive variables back, and have jQuery populate different elements with those variables. I envision being able to achieve this by simply writing: $('.elemA').html($variableA); $('. ...

Ways to showcase the console.log output generated by API calls

//Using Express var express = require('express'); var server = express(); //Utilizing Steam API var SteamWebAPI = require('steamwebapi').SteamWebAPI; SteamWebAPI.setAPIKey('XXXXXXXXXXXXXXXXXXXXXXXXXXXX'); //Retrieving Recent ...

What is the time stamp format of 1651928421543667000?

Recently, I have encountered an issue with an API returning a timestamp as 1651928421543667000. Despite trying various PHP functions like strtotime(), datetime(), and strftime(), I am unable to find the correct format for it. Can anyone provide some guid ...

Creating a setup in TypeScript to enable imports between CommonJS and ES modules (for node-fetch and Express)

I'm facing a challenge in trying to integrate two libraries into a single project: fetch-node, an ES module, and Express, which follows the CommonJS format. The issue arises from needing to import fetch-node using: import fetch from 'node-fetch&a ...

Is there a bug in the iOS platform code causing an unusual problem with valueForKeyPath:@"@max.totalSteps"?

I have been troubleshooting this issue for a few hours, and decided to seek expert advice or clues. Here is the problematic code snippet: NSString *filePath = [[NSBundle mainBundle] pathForResource:@"plot" ofType:@"json"]; NSDictionary *dict = [NSDictiona ...

Guide on linking JSON keys to properties of a class

I have received a JSON response as shown below: { "Robert": [ { "id": "123", "class": "7th", "lastname": "johnson" } ], "William": [ { "id": "124", "class": "7th", "lastname": "parker" } ] } I am l ...

Adjusting the background opacity when the sidebar is open in a React + Typescript project

I am currently working on customizing a sidebar using the react-pro-sidebar library along with React and Typescript. The sidebar layout seems to be in order, but I am facing difficulty in adjusting the background color of the rest of the screen when the si ...

Modifying the name of a key in ng-multiselect-dropdown

this is the example data I am working with id: 5 isAchievementEnabled: false isTargetFormEnabled: true name: "NFSM - Pulse" odiyaName: "Pulse or" when using ng-multiselect-dropdown, it currently displays the "name" key. However, I want ...