3

I am have AWS Lambda function where I am sending a string as my final response

 let abc= `"phone_exist":"0","calls":"0","lastaction":"0"`
 callback(null,abc);

Output: "\"phone_exist\":\"0\",\"calls\":\"0\",\"lastaction\":\"0\""

here I am unable to understand why "\" has been appended in my string.

  1. Can anyone explain me the reason behind this?
  2. Is their a way using which '\' can be removed so I can get in following form

    "phone_exist"="1","calls"="2","lastaction"="3"

1
  • \ is an escape character used to escape ". A simple way to get rid of \ is to add {} at the beginning and the and of the string and use JSON.parse(output). This will convert the result into an object and you can use it directly using calls = output.calls Commented Jul 16, 2018 at 18:54

2 Answers 2

1

You are returning a string, not an object, so Lambda is encoding your string as JSON. What you actually want is most likely this:

let abc = { "phone_exist":"0","calls":"0","lastaction":"0" };
callback(null,abc);

Since those are numbers, you may not want to quote them.

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

Comments

0

The backslash(\) is an escape character for the special character Double Quote(").

Remove them(") from your original string...

Or ignore them as they are just escape characters.

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.