Use JSON objects
  • 28 Nov 2022
  • 1 Minute to read
  • Dark
    Light

Use JSON objects

  • Dark
    Light

Article Summary

Escape special characters in JSON objects

At any point during your workflow run, you may want to turn data in context into a JSON object for easy reference and manipulation. The data may include whitespaces and other special characters that will not be properly interpreted when converted to JSON format. These whitespaces and special characters need to be escaped to keep the data in JSON format.

In the following example, the data contains several newline characters and quotation marks, both of which break JSON objects.

Screenshot of the Output Util step with the input "an example"

An attempt to convert the data to JSON format will fail:
Screenshot of the failed execution log, showing an invalid JSON input message

Use the jsonEscape inline function to escape the special characters in the raw data.
Apply the inline function directly to the data:{{ jsonescape $.raw_data.output }}

A screenshot of the function applied to the data within the Add to JSON step

A JSON object consisting of a single key:value pair is created. The key is data and the value is "\nan \nexample\n". The special characters (newline and quotation marks) are kept and the original string can be easily restored when passing through an HTTP request.

A screenshot of the successful execution log



Was this article helpful?

Changing your password will log you out immediately. Use the new password to log back in.
First name must have atleast 2 characters. Numbers and special characters are not allowed.
Last name must have atleast 1 characters. Numbers and special characters are not allowed.
Enter a valid email
Enter a valid password
Your profile has been successfully updated.