Description
Serializes a value to a JSON string. Handles various data types including objects, arrays, strings, numbers, booleans, andnull.
Syntax
Parameters
Returns
Type: string A JSON string representation of the value. Returnsnull if serialization fails or if the input is undefined.
Examples
Example 1: Serialize a Map
Example 2: Serialize a List
Example 3: Preparing Data for Export
Example 4: Storing JSON in Properties
Notes
- Returns
nullif serialization fails (e.g., circular references) undefinedvalues are normalized tonull- Dates are serialized in ISO format
- Functions and symbols cannot be serialized and will cause
nullreturn - Useful for API responses, data export, or storing complex structures
See Also
- json.fromJsonMap - Parse JSON string to map
- json.fromJsonList - Parse JSON string to list
Frequently Asked Questions
What types can flex.json.toJson serialize?
What types can flex.json.toJson serialize?
It handles maps, lists, strings, numbers, booleans, and
null. It returns null for unsupported types like functions or circular references.How are null and undefined values handled?
How are null and undefined values handled?
null values are serialized as JSON null. undefined values are normalized to null before serialization.