%Encode
This special method converts non-printable and reserved characters to JSON escape sequences.
All special method names and keywords are case-insensitive.
Syntax
%Encode(String, string)
Syntax elements
stringAn expression that evaluates to a string.
Applicability
Internal objects only.
Comments
Characters without explicit escape sequences in JSON use \u followed by the four-digit hexadecimal value of the character.
Character |
DataBasic |
JSON |
---|---|---|
Backspace |
CHAR(08) |
\b |
Tab (horizontal tab) |
CHAR(09) |
\t |
Line feed (newline) |
CHAR(10) |
\n |
Form feed |
CHAR(12) |
\f |
Carriage return |
CHAR(13) |
\r |
Double quote |
" |
\" |
Backslash (reverse solidus) |
\ |
\\ |
Slash (solidus) |
/ |
\/ |
Attribute mark |
@AM |
\u00FE |
Value mark |
@VM |
\u00FD |
Subvalue mark |
@SM |
\u00FC |
Example
Given:
TestObject = %New() TestString = 'TEST\/"':CHAR(08):CHAR(09):CHAR(10):CHAR(11):CHAR(12):CHAR(13):@AM TestObject->Characters = %Encode(String, TestString) CRT TestObject->%ToJSON(1)
which produces:
{ "Characters" : "TEST\\\/\"\b\t\n\u000B\f\r\u00FE" }