JSON_TABLE is an inline table-valued function defined in SQL:2016 and implemented by several vendors. It parses a JSON document and projects selected elements into virtual columns and rows, effectively "shredding" the hierarchical JSON into a relational format. The function is usually used in the FROM clause, where it behaves like a derived table or lateral view that can be joined, filtered, or aggregated. Each column definition specifies a JSON path expression and an optional data type, default value, or ON ERROR/ON EMPTY behavior. When the supplied JSON path points to an array, JSON_TABLE returns one row per array element, enabling set-based processing. Because the output is computed at query time, no persistent table is created; performance therefore depends on the engine's JSON parsing efficiency and indexing support. Caveats: invalid JSON raises errors unless IS JSON or error-handling clauses are used; path expressions are case-sensitive in some dialects; large documents may require dedicated JSON indexes for acceptable speed.
json_expr
- any expression that yields a JSON document or string'json_path'
- root JSON path that selects the portion to be projectedPASSING
- optional list of bind variables to reference inside path expressionsCOLUMNS
- mandatory list that defines output columnscolumn_name
- identifier for the virtual columndata_type
(target SQL type) - INT, VARCHAR, DATE, etc.PATH
- JSON path relative to the root path that extracts the value for the columnDEFAULT
- fallback value if the path is missing or emptyON ERROR / ON EMPTY
- error handling options (NULL, DEFAULT, ERROR)JSON_VALUE, JSON_QUERY, JSON_EXISTS, LATERAL JOIN, CROSS APPLY, OPENJSON (SQL Server)
SQL:2016; first commercial support in Oracle Database 12c Release 2
JSON_VALUE extracts a single scalar value. JSON_TABLE can return multiple columns and rows, making it suitable for set-based operations.
Add ON ERROR NULL or DEFAULT clauses to each column definition, or validate the document with IS JSON before calling JSON_TABLE.
Yes. Use the path '$.array[*]' to iterate over each element, and define columns that map to properties inside the object.
Parsing large JSON can be expensive. Create vendor-specific JSON indexes or persist the shredded data into a table for high-traffic workloads.