JSON_EXTRACT_INT

Overview

Extracts a value from a JSON object by path and returns it as INT. Returns NULL if the path does not exist or the value is null.

Syntax

JSON_EXTRACT_INT(<json>, <path>)

Parameters

  • <json>: JSON type, the source data. Strings must first be converted using PARSE_JSON.
  • <path>: STRING type, a JSONPath expression such as '$.field'.

Examples

SELECT json_extract_int(PARSE_JSON('{"score":42}'), '$.score'); -- 42 -- Path does not exist, returns NULL SELECT json_extract_int(PARSE_JSON('{"score":42}'), '$.other'); -- NULL -- Value is null, returns NULL SELECT json_extract_int(PARSE_JSON('{"score":null}'), '$.score'); -- NULL