Microsoft SQL Server String_escape


SQL Server 2016

Escapes special characters in texts and returns text (nvarchar(max)) with escaped characters.


  1. text. is a nvarchar expression representing the string that should be escaped.

  2. type. Escaping rules that will be applied. Currently the only supported value is 'json'.

\\    "     ', 'json') -- returns '\\\t\/\n\\\\\t\"\t'

List of characters that will be escaped:

Special character    Encoded sequence
Quotation mark (")   \"
Reverse solidus (\)  \\
Solidus (/)          \/
Backspace            \b
Form feed            \f
New line             \n
Carriage return      \r
Horizontal tab       \t

Control character    Encoded sequence
CHAR(0)            \u0000
CHAR(1)            \u0001
...                ...
CHAR(31)           \u001f