Example 3: Escape special characters in source data

This example demonstrates how you can use Mapper Snap to customize source data containing special characters so that it is correctly read and interpreted by downstream Snaps.

Add custom JSON data in the JSON Generator Snap, and the values of field1 and field10 include the special character (').

The output preview of the JSON Generator Snap displays the special character correctly.

Download the pipeline.

Before you send this data to downstream Snaps, you might need to prefix the special characters with an escape character so that downstream Snaps correctly interpret them. You can do this with the Expression field in the Mapper Snap. Based on the accepted escape characters in the endpoint, you can select from the following expressions:

If the Escape Character is 

Use Expression

Sample Output 

If the Escape Character is 

Use Expression

Sample Output 

Single quote (') 

JSON:

$original.mapValues((value,key)=> value.toString().replaceAll("'","''"))

OR

$original.mapValues((value,key)=> value.toString().replaceAll("'","\''"))

CSV:

$[' Business-Name'].replace ("'","''")

Ampersand (&)

 

JSON:

$original.mapValues((value,key)=> value.toString().replaceAll("'","\&'"))

OR

$original.mapValues((value,key)=> value.toString().replaceAll("'","&'"))

CSV:

$[' Business-Name'].replace ("'","&'")

Backslash (\)

 

 

 

JSON:

$original.mapValues((value,key)=> value.toString().replaceAll("'","\\'"))

Backslash is configured as an escape character in SnapLogic®. Therefore, it must itself be escaped to be displayed as text. 

CSV:

$[' Business-Name'].replace ("'","\\'")

Customize the data to be passed to the downstream Snaps using the Mapper Snap Expression field.  Learn more about Escaping Single Quotes in Error Pipeline - Issue.

To successfully reuse pipelines:

  1. Download and import the pipeline into the SnapLogic platform.

  2. Configure Snap accounts, as applicable.

  3. Provide pipeline parameters as applicable.

  File Modified

File Escape_special_characters_in_source_data.slp

Dec 22, 2023 by Kalpana Malladi