Function JsonEncode() Foundation

Converts a character string to JSON text.

Syntax
JsonEncode( <cString> ) -> cJsonString
Parameters
<cString>
<cString> is a character string with the data to encode.
Return

A character string with the JSON text encoded in UTF-8.

Description

The JsonEncode() function converts an Xbase++ character string into JavaScript Object Notation (JSON) text conforming to RFC 7159, Section 7. The returned string is UTF-8 encoded. However, certain characters such as the quotation mark are escaped in the JSON string. These escaped characters appear in the notation "\uXXXX". XXXX is a four-digit hexadecimal number which identifies the corresponding Unicode code point.

The following table lists the characters which are escaped along with their representation in the JSON string.

Escaped characters in JSON strings
Character Escaped representation
" (quotation mark) \U0022
\ (reverse solidus) \U005C
/ (solidus) \U002F
b (backspace) \U0008
f (form feed) \U000C
n (line feed) \U000A
r (carriage return) \U000D
t (tab) \U0009

More information on the JavaScript Object Notation syntax can be found in RFC 7159: https://tools.ietf.org/html/rfc7159#section-7.

Although the resulting JSON text is UTF-8 encoded, attempting to decode it using a normal UTF-8 decoders fails when escaped characters are contained in the string.

Feedback

If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.