0

My JSON is:

body = 
{  
"session_id":"45470003-6b84-4a2b-bf35-e850d1e2df8b",   
"message":"Thanks for calling service desk, may I know the store number you are calling from?", 
"callstatus":"InProgress", 
"intent":"",  
"responseStatusCode":null,  
"responseStatusMsg":null,  
 "context":"getstorenumber"  
}

How to get message value using Node js? Please let me know after testing.
i tried body.message and body['message'] and also body[0]['message']. I am always getting "undefined"

9
  • Check this out -> stackoverflow.com/questions/19013909/… Commented Nov 21, 2017 at 4:28
  • If that's really JSON? If that json was in a javasript variable then either of these will work: body.message and body['message']. Post your actual code. Commented Nov 21, 2017 at 4:29
  • Please add code where you are trying to access. this might be due to asynchronous functions. Commented Nov 21, 2017 at 4:41
  • @RobertMoskal... I will get a JSON response like that when i hit my personal service link, where i have to extract the message part alone. I am sorry i cannot post the full code here. Commented Nov 21, 2017 at 4:46
  • @Dinesh sorry i didn't get you. What code should i add? Commented Nov 21, 2017 at 4:47

1 Answer 1

0

@Chris comment, since the problem is sorted out, Adding the answer to all members for future ref. From node.js result, body is taken as JSON string, using JSON.parse.body converted to json object.

body = 
{  
"session_id":"45470003-6b84-4a2b-bf35-e850d1e2df8b",   
"message":"Thanks for calling service desk, may I know the store number you are calling from?", 
"callstatus":"InProgress", 
"intent":"",  
"responseStatusCode":null,  
"responseStatusMsg":null,  
 "context":"getstorenumber"  
}

JSON.parse.body

console.log(body.message);

Sign up to request clarification or add additional context in comments.

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.