Documentation Center

Escaped strings in queries and in returned items

When constructing your queries, you must escape certain characters in your query strings. Similarly, when processing the items returned by your query, your web application must process any escape strings they may contain that represent things like hard returns or tabs.

Characters represented as escaped strings in JSON

The following characters are represented by escaped strings in JSON:
CharacterEscaped string
Hard return\n
Tab\t
Double quote\"
Backslash\\

Escaping characters in your queries

When constructing a query, ensure that you replace all hard returns, tab characters, double quotes and backslashes are replaced with their escaped strings. This means doubly escaping in your GraphQL calls.

For example, imagine that you have to pass a folder location for an item in a searchByField query. The location is \400 Example Site\Building Blocks\Modules\Core\Admin\. You would escape this path as follows in your searchByField call:
searchByField(indexName: "stagingudp-index", field:"location", value:"\\\\400 Example Site\\\\Building Blocks\\\\Modules\\\\Core\\\\Admin", strict:true, after: "Mg==", first: 10)
In the actual JSON request, this will become the following, singly escaped string:
"publicationTitle": "400 Example Site", "location": "\\400 Example Site\\Building Blocks\\Modules\\Core\\Admin",

Processing escaped strings in your query responses

Imagine that the content you queried contains HTML with hard returns in it, for example:
<p>example</p>
<p style="text-decoration: underline;">important!</p>
<p><strong>some bold statement</strong></p>
<p>A further example</p>
You will get this content returned by GraphQL as one line, with the hard returns represented as the escape string \n:
<p>example</p>\n<p style="text-decoration: underline;">important!</p>\n<p><strong>some bold statement</strong></p>\n<p>A further example</p>

Your code must now replace the \n instances with actual hard returns in order to recreate the original HTML.