0

I am getting this req in my req.body . I want to parse the details .Below is my req.

"[{\"number\":\"INC0010075\",\"cmdb_ci\":\"hubot-test\",\"short_description\":\"test data for buisness rule 30\",\"category\":\"software\",\"comments\":\"\"}]"

I want output like

number:

cmdb_ci:

category:

How do i parse this array object in nodejs. Please help

1
  • You may looking for JSON.parse()??? Commented Sep 8, 2017 at 7:08

3 Answers 3

1

Use JSON.parse() like this:

var aJsonArrString = "[{\"number\":\"INC0010075\",\"cmdb_ci\":\"hubot-test\",\"short_description\":\"test data for buisness rule 30\",\"category\":\"software\",\"comments\":\"\"}]"

var aObjList = JSON.parse(aJsonArrString);
for(var i = 0; i < aObjList.length; i++) {
    console.log('number   : ' + aObjList[i].number);
    console.log('cmdb_ci  : ' + aObjList[i].cmdb_ci);
    console.log('category : ' + aObjList[i].category); 
}
Sign up to request clarification or add additional context in comments.

Comments

1

You Can Use

JSON.parse(req.body);

Comments

0

This looks like JSON, I don't know if the escaping \ are coming from your way of logging the value or something so I'll expect it is a valid string to start off.

You can use

var my_list = JSON.parse(req.body);
//Access like any other array...
my_list[0].number;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.