How do I loop below JSON array in node JS??
[
{
"po_number": "PO1001",
"product_id": "PD1001",
"message": "Exists",
"timestamp": "2016-05-01 10:33:02,123"
},
{
"po_number": "PO1002",
"product_id": "PD1002",
"message": "Does not exist",
"timestamp": "2016-05-01 10:33:03,432"
}
]
Thanks a lot.
asked Nov 8, 2017 at 11:35
user1125829
1793 gold badges4 silver badges13 bronze badges
-
where do you want to pass?Hemant Rajpoot– Hemant Rajpoot2017年11月08日 11:38:10 +00:00Commented Nov 8, 2017 at 11:38
-
@HemantRajpoot I think he means parse.Rick– Rick2017年11月08日 11:40:51 +00:00Commented Nov 8, 2017 at 11:40
-
did you try JSON.parse?Hemant Rajpoot– Hemant Rajpoot2017年11月08日 11:43:26 +00:00Commented Nov 8, 2017 at 11:43
-
@user1125829 Take a look at thisRick– Rick2017年11月08日 11:43:42 +00:00Commented Nov 8, 2017 at 11:43
2 Answers 2
var jsonParsed = JSON.parse(json);
Sign up to request clarification or add additional context in comments.
Comments
Below is the answer.
var resjson = respBody;
resjson.forEach(function(table) {
var ponum = table.po_number;
});
Abdul Manaf
5,01311 gold badges57 silver badges99 bronze badges
answered Nov 8, 2017 at 11:58
user1125829
1793 gold badges4 silver badges13 bronze badges
4 Comments
Himanshu sharma
either your question is wrong . I see your answer , it means how can i iterate over json object . If that is the question change it . Parse means what @minil said.
user1125829
I had respbody json array in the question. With my answer I am able to parse the respbody json array and able to fetch fields like po_number using node js..
Himanshu sharma
your answers shows that json is already parsed and you are just looping it to fetch index data.
user1125829
yes. question is changed to loop instead of parse. Thanks.
lang-js