Inside an Atlas Triggered function, when I use JSON.stringify
or console.log
a property containing the curly quote character, e.g. ’
, the output is changed to â
.
What I did
Configure a Trigger function on a collection and log a property from a document, for example:
exports = async (changeEvent) => {
const property = changeEvent && changeEvent.fullDocument && changeEvent.fullDocument.name
console.log('the string', property)
console.log('the json', JSON.stringify({ name: property }))
}
Create a document in the collection with a curly brace in the name
property, e.g. { "name": "Test’s" }
View the log entry for the create.
What I expect to happen
The log entries should show the text using the curly quote, e.g. the output should be:
the string Test’s
the json {"name":"Test’s"}
What actually happens
The log entries show some other encoding mechanism:
the string Testâs
the json {"name":"Testâs"}
Additional details
This is not just a problem of the function log itself being encoded incorrectly: our trigger function pushes the JSON.stringify
of the document to SQS, and the encoding shows the incorrect Testâs
as well for the message on the SQS queue.