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.2.0

    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.2.0
    iconOceanBase Database
    SQL - V 4.2.0
    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_OBJECT

    Last Updated:2023-10-31 11:17:12  Updated
    Share
    What is on this page
    Purpose
    Syntax
    Parameters
    Examples

    folded

    Share

    Purpose

    JSON_OBJECT() converts a series of key-value pairs passed by using an SQL statement to a JSON object that contains all the input key-value pairs.

    Syntax

    JSON_OBJECT([KEY]'key_name': value_expr FORMAT JSON,
                             'key_name' VALUE value_expr
                             [ABSENT|NULL ON NULL,]
                             [RETURNING  CLOB|BLOB|JSON|VARCHAR2|VARCHAR2[size],]
                             [STRICT,]
                             [WITH UNIQUE KEYS]);
    

    Parameters

    The parameters in the syntax are described as follows:

    • Input forms of key-value pairs:
      1. 'key_name' : value_expression
      2. 'key_name' : "value_string"
      3. 'key_name' VALUE value_expression
      4. 'key_name' VALUE 'value_string'
      5. column_name_x
      6. table_alias.*

    In the first four forms, key-value pairs are defined in KEY : VALUE format. In the fifth form, only one column name is specified, the column name is the key name, and the column content is the value. In the sixth form, the wildcard character * is used, which indicates that all columns of the table are input. This is equivalent to writing all columns of the table in the fifth form.

    • FORMAT JSON: specifies that the return value of the expression is JSON data and no \" will be added to the output result.
    • NULL|ABSENT ON NULL: This clause takes effect only when the calculation result of the expression is NULL.
      • NULL ON NULL: specifies that a JSON NULL value will be used as the value of the given key.
      • ABSENT ON NULL: specifies that the expression will be ignored.
    • WITH UNIQUE KEYS: specifies that the result cannot contain duplicate keys.
    • STRICT: checks whether the output result is in JSON format.
    • RETURNING CLOB|BLOB|JSON|VARCHAR2|VARCHAR2[size]: specifies the return value type. VARCHAR2[size] specifies the length of the return value.

    Examples

    # Use input parameters (a) and (b).
    SELECT JSON_OBJECT(
    'name' : first_name || ' ' || last_name,
    'email' : email,
    'phone' : phone_number,
    'hire_date' : hire_date
    )
        FROM employees
        WHERE employee_id = 140;
    
    # Use the input parameter (f) and the wildcard character.
    SELECT JSON_OBJECT(*) FROM employees WHERE employee_id = 140;
    ---------------------------------------------------------------------
    {
    "EMPLOYEE_ID":140,
    "FIRST_NAME":"Joshua",
    "LAST_NAME":"Patel",
    "EMAIL":"JPATEL",
    "PHONE_NUMBER":"650.121.1834",
    "HIRE_DATE":"2006-04-06T00:00:00",
    "JOB_ID":"ST_CLERK",
    "SALARY":2500,
    "COMMISSION_PCT":null,
    "MANAGER_ID":123,"DEPARTMENT_ID":50
    }
    
    # Use input parameters (c) and (d).
    SELECT JSON_OBJECT('NAME' VALUE first_name, d.*)
       FROM employees e, departments d
          WHERE e.department_id = d.department_id AND e.employee_id =140
    
    # Use the FORMAT JSON clause.
    SELECT JSON_OBJECT ('name' value 'Foo') FROM DUAL;
    +-------------------------------+
    | JSON_OBJECT('NAME'VALUE'FOO') |
    +-------------------------------+
    | {"name":"Foo"}                |
    +-------------------------------+
    
    
    # Use input parameters (a) and (b) and keywords KEY and VALUE.
    SELECT JSON_OBJECT (
        KEY 'deptno' VALUE d.department_id,
        KEY 'deptname' VALUE d.department_name
        ) "Department Objects"
      FROM departments d
      ORDER BY d.department_id;
    
    Department Objects
    ----------------------------------------
    {"deptno":10,"deptname":"Administration"}
    {"deptno":20,"deptname":"Marketing"}
    {"deptno":30,"deptname":"Purchasing"}
    {"deptno":40,"deptname":"Human Resources"}
    {"deptno":50,"deptname":"Shipping"}
    
    # Use input parameters (1) and (2).
    SELECT JSON_OBJECT(
    'first_name' VALUE first_name,
    'last_name' VALUE last_name,
    'email' VALUE email,
    'hire_date' VALUE hire_date
    )
    FROM employees
    WHERE employee_id = 140;
    ---------------------------------------------------------------------------
    {
    "first_name":"Joshua",
    "last_name":"Patel",
    "email":"JPATEL",
    "hire_date":"2006-04-06T00:00:00"
    }
    

    Previous topic

    JSON_ARRAY
    Last

    Next topic

    JSON_ARRAYAGG
    Next
    What is on this page
    Purpose
    Syntax
    Parameters
    Examples