Function Var2Json() Foundation

Converts an array or object to JSON text.

Syntax
Var2Json( <aoValue> ) -> cJson
Parameters
<aoValue>
<aoValue> is an array or object to be converted to JSON text.
Return

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

Description

Var2Json() converts objects and arrays to their JavaScript Object Notation (JSON) representation.

JSON is a lightweight data exchange format. It is easy for people to read and write and is based on a subset of the JavaScript programming language. JSON is a text format that is completely programming language independent. These features make JSON an ideal data exchange language for web applications.

The function Var2JSon() can handle nested values, such as an array of objects with their members which in turn may also be arrays or objects. However, Var2JSon() cannot detect circular references. For example, passing in an object which references itself in one of its members is not supported.

JSON supports only array and object as the root data type. Therefore, passing a scalar value such as a string in <aoValue> is not supported. However, object members and array elements may contain values of any Xbase++ (including scalar) data type.

The Xbase++ data types date and codeblock are not covered by the JSON specification. The following table lists the transformations applied for these and the other Xbase++ data types:

Transformation of Xbase++ data types
Data Type Representation in cJson
Array Ordered list of values
Character JSON string literal, see JsonEncode()
Codeblock Expression as JSON string
Date ISO 8601 date value as recommended by JSON schema
Logical JSON literal true / false
Numeric Numeric with optional minus sign, fraction and/or exponent part. Precision is equivalent to Xbase++ numeric type.
Object Collection of name/value pairs
Undefined JSON literal null

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.