JSON_EXTRACT_SCALAR
All functions > JSON > JSON_EXTRACT_SCALAR
Returns the scalar value of the given JSON path in the given JSON expression.
Syntax
JSON_EXTRACT_SCALAR(expr, json_path)
sql
Arguments
Parameter | Type | Required | Description |
---|---|---|---|
expr | JSON | Yes | The JSON expression to extract from |
json_path | VARCHAR | Yes | The JSON path to extract (e.g., '$.field') |
Returns
The scalar value as VARCHAR at the specified path
Notes
- Extracts scalar values from JSON as strings
- Converts JSON primitives (strings, numbers, booleans) to VARCHAR
- Supports nested field access with dot notation
- Supports array indexing ($.array[0])
- Returns NULL if the path doesn't exist
- Returns NULL if the value is not a scalar (object or array)
- Use JSON_EXTRACT to preserve JSON structure
- JSONPath starts with $ representing the root