- Newest
- Most votes
- Most comments
The issue you're experiencing with the apostrophe in "O'Donnell" causing a serialization exception is related to how special characters are handled in JSON processing between API Gateway and Step Functions.
In the Amazon States Language, certain characters are reserved for Intrinsic Functions and must be escaped, including the single quote ('). When these characters appear in your data and aren't properly escaped, they can cause serialization errors.
To fix this issue, try the following solution in your API Gateway integration request mapping template:
"input": "$util.escapeJavaScript($input.json('
The issue you're experiencing with the apostrophe in "O'Donnell" causing a serialization exception is related to how special characters are handled in JSON processing between API Gateway and Step Functions.
In the Amazon States Language, certain characters are reserved for Intrinsic Functions and must be escaped, including the single quote ('). When these characters appear in your data and aren't properly escaped, they can cause serialization errors.
To fix this issue, try the following solution in your API Gateway integration request mapping template:
```
"input": "$util.escapeJavaScript($input.json('$')).replaceAll("\\'", "'")"
```
This solution uses `escapeJavaScript` to properly escape the JSON, then specifically replaces the escaped single quotes (`\'`) with regular single quotes (`'`). This prevents the serialization error while maintaining the integrity of your data.
If you're still experiencing issues, you might need to handle newlines as well:
```
"input": "$util.escapeJavaScript($input.json('$')).replaceAll("\n", "").replaceAll("\\'", "'")"
```
This approach removes any newlines in the payload and then handles the single quote escaping, which has been found to resolve similar serialization issues when passing data with apostrophes from API Gateway to Step Functions.
#39;)).replaceAll("\\'", "'")"
This solution uses escapeJavaScript to properly escape the JSON, then specifically replaces the escaped single quotes (\') with regular single quotes ('). This prevents the serialization error while maintaining the integrity of your data.
If you're still experiencing issues, you might need to handle newlines as well:
"input": "$util.escapeJavaScript($input.json('
The issue you're experiencing with the apostrophe in "O'Donnell" causing a serialization exception is related to how special characters are handled in JSON processing between API Gateway and Step Functions.
In the Amazon States Language, certain characters are reserved for Intrinsic Functions and must be escaped, including the single quote ('). When these characters appear in your data and aren't properly escaped, they can cause serialization errors.
To fix this issue, try the following solution in your API Gateway integration request mapping template:
```
"input": "$util.escapeJavaScript($input.json('$')).replaceAll("\\'", "'")"
```
This solution uses `escapeJavaScript` to properly escape the JSON, then specifically replaces the escaped single quotes (`\'`) with regular single quotes (`'`). This prevents the serialization error while maintaining the integrity of your data.
If you're still experiencing issues, you might need to handle newlines as well:
```
"input": "$util.escapeJavaScript($input.json('$')).replaceAll("\n", "").replaceAll("\\'", "'")"
```
This approach removes any newlines in the payload and then handles the single quote escaping, which has been found to resolve similar serialization issues when passing data with apostrophes from API Gateway to Step Functions.
#39;)).replaceAll("\n", "").replaceAll("\\'", "'")"
This approach removes any newlines in the payload and then handles the single quote escaping, which has been found to resolve similar serialization issues when passing data with apostrophes from API Gateway to Step Functions.
Sources
Amazon States Language
Event Bridge Rule and Single-Quote Escaping | AWS re:Post

Thank you so much, your solution worked.