How to Escape JSON Content in the Message shape

Document created by mike_aronson Employee on Jul 21, 2015Last modified by Adam Arrowsmith on Aug 10, 2016
Version 4Show Document
  • View in full screen mode
JSON syntax contains special characters including curly braces { } and double quotation marks " " that conflict with reserved characters in the Message shape used to interpret parameters or handle strings.

Options include:

  1. Do not use the Message shape to fabricate the JSON data for testing or troubleshooting
  2. Read the test data from a file (e.g. disk, FTP)
  3. Wrap the entire JSON content with single quotes
In looking at option 3, for example, this sample JSON content...

 

{
  "type": "company",
  "name": "Company ABC",
  "location": {
    "state": "PA",
    "country": "USA"
  }
}

 

...should be wrapped in single quotes for the curly braces to avoid being interpreted as replacement variables in a Message shape:

 

'{

  "type": "company",

  "name": "Company ABC",

  "location": {

    "state": "PA",

    "country": "USA"

  }

}'

 

Taking it one step further, if you did want to use replacement variables in the Message shape to insert dynamic content, you can use additional single quotes to "toggle off" the escaping.

 

For example (note the single quotes around the {1} placeholder):

 

'{

  "type": "company",

  "name": "Company ABC",

  "location": {

    "state": "PA",

    "country": "USA"

  },

  "currentDate": "'{1}'"

}'

 

15 people found this helpful

Attachments

    Outcomes