Accessing JSON object properties directly and log it

how to get key and value from json array object in javascript
get value from json object in javascript
how to get value from json array object in javascript
loop through json object
how to get value from json object in angular 6
json stringify
get key value from json object in java
jsonobject

I'm trying to access JSON Object properties directly and log it, here is my function :

loadProcesses(filter?){

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

});

So this.processListe contain a JSON Object, and my JSON format is like this:

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

So it will contains exactly the same things, for example if i want to simply print the label on a console log how can i do it ??

Are you looking for something like this:

function parseObject(obj)
{
   for(var key in obj)
   {
      console.log("key: " + key + ", value: " + obj[key])
      if(obj[key] instanceof Object)
      {
        parseObject(obj[key]);
      }
   }
}

Back to basics: JSON Syntax and Tips, literal names MUST be lowercase (ie – null, false, true etc). JSON objects are surrounded by curly braces {}. JSON objects are written in key/value pairs. Keys must be strings, and values must be a valid JSON data type (string, number, object, array, boolean or null). Keys and values are separated by a colon. Each key/value pair is separated by a comma.

parse it and access the fields.

var obj = JSON.parse(filter);
obj.Person.id; 
//etc

How to access an array in an object in JS, now how can u get property inside it. im working on a javascript file and i get error message Unexpected number. Vote Up0  how to access JSON object in C# [duplicate] This allows you to access the properties within pretty easily, like so: Parse JSON String to JSON Object in C#.NET-3.

parse it in the .subscribe:

res => this.processListe = res.json();

How to access JSON object in JavaScript – Mkyong.com, Keys must be strings, and values must be a valid JSON data type (string, number, object In a for-in loop, use the bracket notation to access the property values:  Accessing nested data structures. A nested data structure is an array or object which refers to other arrays or objects, i.e. its values are arrays or objects. Such structures can be accessed by consecutively applying dot or bracket notation.

a better solution is to declare your response with any :

loadProcesses(filter?){

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

});

this way you can access any attirbute in your response

JSON Objects, Reflecting over JavaScript object properties, or more commonly What's not so straight forward is if you want to get both the value as well as key2 var key = Object.keys(o)[idx]; value = o[key] console.log(key,value); // key2 value2 a good structure to filter or search because of the clunky object parsing  The delete keyword deletes both the value of the property and the property itself. After deletion, the property cannot be used before it is added back again. The delete operator is designed to be used on object properties. It has no effect on variables or functions. The delete operator should not be used on predefined JavaScript

Getting JavaScript Properties for Object Maps by Index or Name , JSON is a text-based data format following JavaScript object syntax, which was popularized by Douglas Crockford. Inside this object, we want to access the powers property, so we use ["powers"] . set the XHR request to convert the JSON response directly into a JavaScript object using: Sign up now. The JSON.stringify() function converts an object to a JSON string. Strings are useful for transporting data from a client to a server through storing or passing information in a lightweight way. For example, you may gather a user’s settings on the client side and then send them to a server.

Working with JSON, An array of strings that corresponds to the properties found directly in the forEach( function (val, idx, array) { console.log(val + ' -> ' + obj[val]); }  Parsing JSON Object using JObject.Parse. Parsing all JSON using JToken.Parse. Deserializing from JSON with LINQ. Using JObject.Properties

Object.getOwnPropertyNames(), I am able to output some JSON using console.log(this.state.coinList.Data);. It outputs the JSON object, but I am unable to console.log properties  The above example was simple in terms of accessing the JavaScript object, because we set the XHR request to convert the JSON response directly into a JavaScript object using: request.responseType = 'json'; But sometimes we aren't so lucky — sometimes we receive a raw JSON string, and we need to convert it to an object ourselves.

Comments
  • I added a better solution in the responses below :)
  • thank you man, it did show up only the first Propretie it's an object that contains under it it own propertie,, how can i access the sub properties in thos case please ??
  • Edited my answer to support nested json
  • thank you a lot, i'll reform it to my needs thank you again
  • i did change my function as you mentioned, and i'm having this error : angular2.dev.js:1206 Uncaught SyntaxError: Unexpected token o in JSON at position 1, this is what i did : subscribe( res=> { this.processListe = res; this.obj = JSON.parse(res); console.log("++++ value is :++++++++" + this.obj.id); }
  • thank you for the answer, i'm having this error : angular2.dev.js:1206 Uncaught TypeError: res.json is not a function and this is my new function : .subscribe( res=> { this.processListe = res.json(); console.log("++++ value is :++++++++" + this.processListe.id); }