OceanBase logo

OceanBase

A unified distributed database ready for your transactional, analytical, and AI workloads.

Product Overview
DEPLOY YOUR WAY

OceanBase Cloud

The best way to deploy and scale OceanBase

OceanBase Enterprise

Run and manage OceanBase on your infra

TRY OPEN SOURCE

OceanBase Community Edition

The free, open-source distributed database

OceanBase seekdb

Open source AI native search database

Customer Stories

Real-world success stories from enterprises across diverse industries.

View All
BY USE CASES

Mission-Critical Transactions

Global & Multicloud Application

Elastic Scaling for Peak Traffic

Real-time Analytics

Active Geo-redundancy

Database Consolidation

Resources

Comprehensive knowledge hub for OceanBase.

Blog

Live Demos

Training & Certification

Documentation

Official technical guides, tutorials, API references, and manuals for all OceanBase products.

View All
PRODUCTS

OceanBase Cloud

OceanBase Database

Tools

Connectors and Middleware

QUICK START

OceanBase Cloud

OceanBase Database

BEST PRACTICES

Practical guides for utilizing OceanBase more effectively and conveniently

Company

Learn more about OceanBase – our company, partnerships, and trust and security initiatives.

About OceanBase

Partner

Trust Center

Contact Us

International - English
中国站 - 简体中文
日本 - 日本語
Sign In
Start on Cloud

OceanBase

A unified distributed database ready for your transactional, analytical, and AI workloads.

Product Overview
DEPLOY YOUR WAY

OceanBase Cloud

The best way to deploy and scale OceanBase

OceanBase Enterprise

Run and manage OceanBase on your infra

TRY OPEN SOURCE

OceanBase Community Edition

The free, open-source distributed database

OceanBase seekdb

Open source AI native search database

Customer Stories

Real-world success stories from enterprises across diverse industries.

View All
BY USE CASES

Mission-Critical Transactions

Global & Multicloud Application

Elastic Scaling for Peak Traffic

Real-time Analytics

Active Geo-redundancy

Database Consolidation

Comprehensive knowledge hub for OceanBase.

Blog

Live Demos

Training & Certification

Documentation

Official technical guides, tutorials, API references, and manuals for all OceanBase products.

View All
PRODUCTS
OceanBase CloudOceanBase Database
ToolsConnectors and Middleware
QUICK START
OceanBase CloudOceanBase Database
BEST PRACTICES

Practical guides for utilizing OceanBase more effectively and conveniently

Learn more about OceanBase – our company, partnerships, and trust and security initiatives.

About OceanBase

Partner

Trust Center

Contact Us

Start on Cloud
编组
All Products
    • Databases
    • iconOceanBase Database
    • iconOceanBase Cloud
    • iconOceanBase Tugraph
    • iconInteractive Tutorials
    • iconOceanBase Best Practices
    • Tools
    • iconOceanBase Cloud Platform
    • iconOceanBase Migration Service
    • iconOceanBase Developer Center
    • iconOceanBase Migration Assessment
    • iconOceanBase Admin Tool
    • iconOceanBase Loader and Dumper
    • iconOceanBase Deployer
    • iconKubernetes operator for OceanBase
    • iconOceanBase Diagnostic Tool
    • iconOceanBase Binlog Service
    • Connectors and Middleware
    • iconOceanBase Database Proxy
    • iconEmbedded SQL in C for OceanBase
    • iconOceanBase Call Interface
    • iconOceanBase Connector/C
    • iconOceanBase Connector/J
    • iconOceanBase Connector/ODBC
    • iconOceanBase Connector/NET
icon

OceanBase Database

SQL - V4.4.2

    Download PDF

    OceanBase logo

    The Unified Distributed Database for the AI Era.

    Follow Us
    Products
    OceanBase CloudOceanBase EnterpriseOceanBase Community EditionOceanBase seekdb
    Resources
    DocsBlogWhite PaperLive DemosTraining & CertificationTicket
    Company
    About OceanBaseTrust CenterLegalPartnerContact Us
    Follow Us

    © OceanBase 2026. All rights reserved

    Cloud Service AgreementPrivacy PolicySecurity
    Contact Us
    Document Feedback
    1. Documentation Center
    2. OceanBase Database
    3. SQL
    4. V4.4.2
    iconOceanBase Database
    SQL - V 4.4.2
    Databases
    • OceanBase Database
    • OceanBase Cloud
    • OceanBase Tugraph
    • Interactive Tutorials
    • OceanBase Best Practices
    Tools
    • OceanBase Cloud Platform
    • OceanBase Migration Service
    • OceanBase Developer Center
    • OceanBase Migration Assessment
    • OceanBase Admin Tool
    • OceanBase Loader and Dumper
    • OceanBase Deployer
    • Kubernetes operator for OceanBase
    • OceanBase Diagnostic Tool
    • OceanBase Binlog Service
    Connectors and Middleware
    • OceanBase Database Proxy
    • Embedded SQL in C for OceanBase
    • OceanBase Call Interface
    • OceanBase Connector/C
    • OceanBase Connector/J
    • OceanBase Connector/ODBC
    • OceanBase Connector/NET
    SQL
    KV
    • V 4.6.0
    • V 4.4.2
    • V 4.3.5
    • V 4.3.3
    • V 4.3.1
    • V 4.3.0
    • V 4.2.5
    • V 4.2.2
    • V 4.2.1
    • V 4.2.0
    • V 4.1.0
    • V 4.0.0
    • V 3.1.4 and earlier

    `JSON_TABLE`

    Last Updated:2026-04-14 12:43:57  Updated
    Share
    What is on this page
    Purpose
    Syntax
    Considerations
    Examples
    Parse user input data
    Extract data from a table
    Create a view
    Insert data into a table
    References

    folded

    Share

    Purpose

    JSON_TABLE() can extract required information from nested JavaScript Object Notation (JSON) data based on the specified path.

    It converts the extracted semi-structured JSON data into structured data. To be specific, the function extracts data from a JSON document and returns it as a relational table with specified columns. It creates a clear table schema by mapping different parts of the JSON data to the rows and columns of a virtual table. This facilitates query operations and allows you to insert the data into a new table or view for further processing.

    JSON_TABLE() provides column output for each JSON value, and provides multi-row (multi-column) output for a JSON array.

    Syntax

    JSON_TABLE(expr, path_literal COLUMNS (column_list)) [AS] alias
    
    column_list:
        column[, column...]
    
    column:
        column_name FOR ORDINALITY
        | column_name data_type PATH path_literal [json_value_on_empty_clause] [json_value_on_error_clause]
        | column_name data_type EXISTS PATH path_literal
        | NESTED [PATH] path_literal COLUMNS (column_list)
    
    json_value_on_empty_clause:
        {NULL | DEFAULT json_string | ERROR} ON EMPTY
    
    json_value_on_error_clause:
        {NULL | DEFAULT json_string | ERROR} ON ERROR
    

    Considerations

    JSON_TABLE() must be used in the FROM clause of a SELECT statement.

    The arguments in the syntax of the JSON_TABLE() function are described as follows:

    • expr: the expression that evaluates to JSON data. If the expression does not evaluate to JSON data, an error is reported.

    • path_literal: the string that specifies the JSON path. If you set the parameter to a value of other types or an invalid path, an error is reported.

    • column_list: the list of column definitions. The expression must include at least one column definition; otherwise, an error is reported.

    • column: the specific column definition. The following column definition syntaxes are supported:

      • column_name FOR ORDINALITYFOR: provides an ID for a row. column_name is a column of the INT type.

      • column_name data_type PATH path_literal [json_value_on_empty_clause] [json_value_on_error_clause]: extracts JSON data from path_literal and forcibly converts the data to the column type. A missing value triggers the optional clause json_value_on_empty_clause.

      • column_name data_type EXISTS PATH path_literal: returns 1 if any data exists in the path specified by path_literal, and 0 if otherwise.

      • NESTED [PATH] path_literal COLUMNS (column_list): indicates a nested structure where column of any of the other three column definition syntaxes can be further defined.

    • data_type: the data type. OceanBase Database in MySQL-compatible mode supports all data types except ENUM and SET.

    • alias: the table alias.

    • json_value_on_empty_clause: the expected behavior performed when the data filtered by the path is empty. Valid values:

      • NULL ON EMPTY: sets the column to NULL, which is the default behavior.
      • DEFAULT json_string: parses json_string as the default value to replace the missing JSON object or array. OceanBase Database allows you to use a constant of any type as the default value.
      • ERROR ON EMPTY: throws an error.
    • json_value_on_error_clause: the expected behavior performed to override an error that occurs during expression evaluation. The valid values are the same as those of json_value_on_empty_clause.

      The optional clause json_value_on_error_clause is triggered in the following scenarios:

      • expr does not evaluate to properly formatted JSON data.

      • The JSON path expression points to a non-scalar value.

      • The JSON path expression points to no data.

      • The length of the data type specified for the return value is not large enough to hold the return value.

    Examples

    Parse user input data

    The following example parses the JSON data entered by a user and returns a relational table.

    SELECT * FROM
      JSON_TABLE(
        '[{"x":"3"},{"a":2},{"b":1},{"a":0},{"a":[1,2]}]',
        '$[*]' COLUMNS (id FOR ORDINALITY,
                 jpath VARCHAR(100) PATH '$.a'
                    DEFAULT '33' ON EMPTY
                    DEFAULT '66' ON ERROR,
                 jsn_path JSON PATH '$.a' DEFAULT '{"x":33}' ON EMPTY,
                 jexst INT EXISTS PATH '$.b')
      ) AS tt;
    

    The query result is as follows:

    +------+-------+-----------+-------+
    | id   | jpath | jsn_path  | jexst |
    +------+-------+-----------+-------+
    |    1 | 33    | {"x": 33} |     0 |
    |    2 | 2     | 2         |     0 |
    |    3 | 33    | {"x": 33} |     1 |
    |    4 | 0     | 0         |     0 |
    |    5 | 66    | [1, 2]    |     0 |
    +------+-------+-----------+-------+
    5 rows in set
    

    Extract data from a table

    The following example extracts JSON data from a table and returns a relational table.

    DROP TABLE IF EXISTS t1;
    
    CREATE TABLE t1(id INT, jd JSON);
    
    INSERT INTO t1 VALUES (1, '[1,3,5]'),(2,'[2,4,6]');
    
    SELECT id, jt.* FROM t1,
      JSON_TABLE(jd, '$[*]' COLUMNS (jid FOR ORDINALITY,
                                     val INT PATH '$')) AS jt;
    
    SELECT /*+ JOIN_ORDER(jt, t1) */ id, jt.*
      FROM t1,
      JSON_TABLE(jd, '$[*]' COLUMNS (jid FOR ORDINALITY,
                                     val INT PATH '$')) AS jt;
    

    The query result is as follows:

    +------+------+------+
    | id   | jid  | val  |
    +------+------+------+
    |    1 |    1 |    1 |
    |    1 |    2 |    3 |
    |    1 |    3 |    5 |
    |    2 |    1 |    2 |
    |    2 |    2 |    4 |
    |    2 |    3 |    6 |
    +------+------+------+
    6 rows in set
    

    Create a view

    The following example generates a view based on the values returned by the JSON_TABLE() function.

    CREATE VIEW v1 AS
      SELECT * FROM JSON_TABLE('[{"a": 1, "b": 2}]',
                               '$[*]' COLUMNS ( a INT PATH '$.b')) AS jt;
    
    SELECT * FROM v1;
    

    The query result is as follows:

    +------+
    | a    |
    +------+
    |    2 |
    +------+
    1 row in set
    

    Check the view definition.

    SHOW CREATE VIEW v1;
    
    DROP VIEW v1;
    

    The query result is as follows:

    +------+-----------------------------------------------------------------------------------------------------------------------------------+----------------------+----------------------+
    | View | Create View                                                                                                                       | character_set_client | collation_connection |
    +------+-----------------------------------------------------------------------------------------------------------------------------------+----------------------+----------------------+
    | v1   | CREATE VIEW `v1` AS select `jt`.`a` AS `a` from JSON_TABLE('[{\"a\": 1, \"b\": 2}]' , '$[*]' columns (a INTEGER  path '$.b' )) jt | utf8mb4              | utf8mb4_general_ci   |
    +------+-----------------------------------------------------------------------------------------------------------------------------------+----------------------+----------------------+
    1 row in set
    

    Insert data into a table

    The following example inserts the values returned by the JSON_TABLE() function into a table.

    DROP TABLE IF EXISTS t2;
    
    CREATE TABLE t2(id INT, a TINYINT, b VARCHAR(5), c DATE, d DECIMAL);
    
    INSERT INTO t2 SELECT * FROM
      JSON_TABLE(JSON_ARRAY(JSON_OBJECT('a', 1, 'b', 'abc'),
                            JSON_OBJECT('a', 2, 'b', 'abcd'),
                            JSON_OBJECT('a', 1000, 'b', 'xyz'),
                            JSON_OBJECT('c', TIME'12:00:00', 'd', 1e308)),
                 '$[*]' COLUMNS (id FOR ORDINALITY,
                                 a TINYINT PATH '$.a' DEFAULT '111' ON ERROR,
                                 b VARCHAR(5) PATH '$.b' DEFAULT '"ERR"' ON ERROR,
                                 c DATE PATH '$.c' DEFAULT '"2001-01-01"' ON ERROR,
                                 d DECIMAL PATH '$.c' DEFAULT '999' ON ERROR)
                ) AS jt;
    
    SELECT * FROM t2 ORDER BY id;
    DROP TABLE t2;
    

    The query result is as follows:

    +------+------+------+------------+-------+
    | id   | a    | b    | c          | d     |
    +------+------+------+------------+-------+
    |    1 |    1 | abc  | NULL       |  NULL |
    |    2 |    2 | abcd | NULL       |  NULL |
    |    3 |  111 | xyz  | NULL       |  NULL |
    |    4 | NULL | NULL | 2001-01-01 | 43200 |
    +------+------+------+------------+-------+
    4 rows in set
    

    References

    Overview of JSON data types

    Previous topic

    JSON_VALID
    Last

    Next topic

    JSON_PRETTY
    Next
    What is on this page
    Purpose
    Syntax
    Considerations
    Examples
    Parse user input data
    Extract data from a table
    Create a view
    Insert data into a table
    References