// strings reference

SQL JSON_TABLE function

JSON_TABLE(doc, '$[*]' COLUMNS (...)) turns a JSON array into rows you can join, filter and group. The COLUMNS clause declares a type and path for each output column.

Categoria
Strings
Returns
rowset
In this category
155 of 172

Sintaxe

JSON_TABLE(expr, path COLUMNS (col type PATH '$.x', ...))

Suporte a mecanismos

MotorSupportNotas
SQL Server Not built in no JSON_TABLE; OPENJSON WITH is the dialect's answer
PostgreSQL Different name or syntax PostgreSQL 17+
MySQL Sim Supported under this name.
SQLite Not built in json_each for one level of shredding
Oracle Sim Supported under this name.

Exemplos

Oracle

SELECT jt.sku, jt.qty
FROM orders o,
JSON_TABLE(o.items, '$[*]'
  COLUMNS (sku VARCHAR2(40) PATH '$.sku',
           qty NUMBER PATH '$.qty')) jt;

MySQL

SELECT jt.sku, jt.qty
FROM imports i,
JSON_TABLE(i.items, '$[*]'
  COLUMNS (sku CHAR(40) PATH '$.sku',
           qty INT PATH '$.qty')) jt;

Bom saber

  • COLUMNS entries take PATH for location, EXISTS PATH for a 0/1 presence flag, FOR ORDINALITY for a row number, and NESTED PATH to unroll a child array into extra rows.
  • Missing and unconvertible values become NULL by default: a qty of "abc" in an INT column returns NULL on MySQL and Oracle without an error. Add ERROR ON ERROR (and ERROR ON EMPTY) to a column when bad data should stop the query.
  • SQL Server never received JSON_TABLE: OPENJSON WITH covers flat arrays; nested arrays take CROSS APPLY chains.

Questions about JSON_TABLE

How do I flatten an array of objects?

That is JSON_TABLE's core case: '$[*]' as the row pattern, one COLUMNS entry per object key. Nested arrays inside each element take a NESTED PATH clause.

JSON_TABLE or OPENJSON?

Whichever your engine has: JSON_TABLE on Oracle, MySQL and PostgreSQL 17, OPENJSON on SQL Server. JSON_TABLE handles nested arrays inside one call with NESTED PATH; OPENJSON chains CROSS APPLY per level.

Browse every function in the SQL function reference, or see what the SQLly desktop app does for your database.

Cheat sheets for the engines that have it: PostgreSQL, MySQL, Oracle.

// fewer lookups

Functions your engine actually has

SQLly's completion lists the built-in functions of the engine you're connected to, whether that's SQL Server, PostgreSQL, MySQL, SQLite or Oracle. Hover a function for help, and signature hints show each argument as you type.