0

Getting Lambda Response as follows, which is double encoded.

"{\"id\":\"6EE1DDABDC5C5EB271289A057DDA82B1\",\"name\":\"Test\",\"stateName\":\"INITIAL\",\"description\":\"Test Description\",\"type\":\"Download\",\"createTime\":\"Aug 10, 2018 2:02:02 PM\",\"updateTime\":\"Aug 10, 2018 2:02:02 PM\"}"

However it shows fine when I print it under the handleRequest(Object input, Context context) method.

{"id":"6EE1DDABDC5C5EB271289A057DDA82B1","name":"Test","stateName":"INITIAL", "description":"Test Description","type":"Test","createTime":"Aug 10, 2018 2:02:02 PM", "updateTime":"Aug 10, 2018 2:02:02 PM"}

Any solutions to make it appear correctly in the response?

2 Answers 2

4

Your lambda returns json, which is really just a string that is valid json you can decode. But the lambda response is also json. So to send your json within the lambda response object, it is included as a string. It's not wrong in my mind to call this "double encoded", and just like the name implies, you'll have to decode twice as well: one for the outside json and once for the inside Json.

When you print from inside the lambda, your response hasn't been encoded into a containing json object, which is why it isn't double encoded there.

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

1 Comment

Thanks. I found a fix for the problem. The following code fixed the double encoded issue. import org.apache.commons.lang.StringEscapeUtils; String decodedJson = StringEscapeUtils.unescapeJava(encodedJson);
1

I recently solved this problem by changing my Lambda function to return a Java Object - I created a response class that had public get methods, which the Lambda runtime converted to JSON. No doubly-encoded JSON. Not sure why this isn't documented.

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.