Skip to main content

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

Output:

Example 2: Parsing Stored JSON Properties

Example 3: Processing API Responses

Example 4: Handling Malformed JSON

Output:
(Returns empty map for invalid 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

Frequently Asked Questions

It safely returns an empty map {} without throwing an exception, making it safe to use without error handling.
Yes. Once parsed, you can use dot notation to access nested properties, e.g., parsed.field1.