Sambuddha Sambuddha - 11 months ago 73
JSON Question

Iterate through JSON object using DOJO or javascript

I have my json object coming from ajax resaponse.It looks like this.

{ "customerID": "87545", "parentCustomerID": "Parent:87545",

"relationshipID": "87545-- Rel 1234", "customerName": "87545-- John
Snow", "constitution": "87545-- consti" }

Now I want to iterate through this either using DOJO 1.10 library or normal for loop javascript.But I am not able to get the loop through. I have tried the approach for

require(["dojo/_base/array"], function(array){
array.forEach(JSON.stringify(ajaxJsonData), function(entry, i){


Can anyont please help me ?

NB: this json object is coming dynamically each time and the keys are the same as the id of the input types in my jsp page. So i need to get the key and the value.


You can use the following in Javascript:

var obj = { "customerID": "87545", "parentCustomerID": "Parent:87545",
"relationshipID": "87545-- Rel 1234", "customerName": "87545-- John Snow", "constitution": "87545-- consti" };

for (var key in obj) {

   console.log(key +":" +obj[key]);


Explanation: It will iterate over all the keys present in obj and print it along with the corresponding value in the obj using obj[key].

You can check the results by copying the above code in your browser's console.