Description
Parses a JSON string and returns it as a map (object). Safely handles malformed JSON by returning an empty map on parse errors.Syntax
Parameters
Returns
Type: map (object) A map parsed from the JSON string. Returns an empty map{} if parsing fails or if the input is not a valid JSON object.
Examples
Example 1: Basic JSON Parsing
Example 2: Parsing Stored JSON Properties
Example 3: Processing API Responses
Example 4: Handling Malformed JSON
Notes
- Returns empty map
{}if input is not valid JSON - Returns empty map if the JSON represents a non-object value (e.g., array, string)
- Safe to use without error handling as it won’t throw exceptions
- Useful for parsing configuration, API responses, or stored JSON data
See Also
- json.fromJsonList - Parse JSON string to list
- json.toJson - Serialize value to JSON string
Frequently Asked Questions
What does flex.json.fromJsonMap return for invalid JSON?
What does flex.json.fromJsonMap return for invalid JSON?
It safely returns an empty map
{} without throwing an exception, making it safe to use without error handling.Can I access nested properties from the parsed map?
Can I access nested properties from the parsed map?
Yes. Once parsed, you can use dot notation to access nested properties, e.g.,
parsed.field1.