Search notes:

Oracle SQL/JSON

Query functions to produce SQL values from JSON documents:
Predicates
Generation functions
Updating JSON data
Oracle defines some PL/SQL object types for JSON.
Misc
json_serialize() Returns a textual representation of a JSON document
json_scalar() Returns a scalar type
json_equal() Tests if two JSON values are equal
json_dataguide() An aggregate function

Creating a table for JSON documents

JSON documents can be stored in columns whose data type is one of
create table tq84_json_documents (
   id   number generated always as identity,
   doc  clob,
   --
   constraint json_doc_pk primary key (id),
   constraint doc_is_json check(doc is json)
);

insert into tq84_json_documents (doc) values ('{num: 1}');
 
-- check constraint violation
-- insert into tq84_json_documents (doc) values ('{num: }');

Querying JSON data

select
   *
from
   json_table('
{
   "num"    :     42,
   "txt"    :     "Hello world",
   "ary"    :    ["elem_0", 1]
}',
'$'
   columns (
      num             number                   path '$.num'   ,
      txt             varchar2(20)             path '$.txt'   ,
      ary             varchar2(20) FORMAT JSON path '$.ary'   ,
      ary_1st_elem    varchar2(20)             path '$.ary[0]',
      ary_2nd_elem    number                   path '$.ary[1]'
   )
);
The following JSON document is very similar to the previous one - but it contains an array of objects. Using $[*] returns a record for each of these objects:
select
   *
from
   json_table('
[
   {
      "num"    :     42,
      "txt"    :    "Hello world",
      "ary"    :   ["elem_0", 1]
   },
   {
      "num"    :     99,
      "txt"    :    "ninety-nine",
      "ary"    :   ["red balllons", 55.5]
   },
   {
      "num"    :     17,
      "txt"    :    "xyz",
      "ary"    :   ["abc", 1.7]
   }
]',
  '$[*]'  -- Note the [*]
   columns (
      num             number                   path '$.num'   ,
      txt             varchar2(20)             path '$.txt'   ,
  --  ary             varchar2(20) format json path '$.ary'   ,
      ary_1st_elem    varchar2(20)             path '$.ary[0]',
      ary_2nd_elem    number                   path '$.ary[1]'
   )
);

OSON

OSON is Oracle's optimized (binary) format for fast query and update of JSON documents/data.

Misc / TODO

Because Oracle treats a string with no characters ('') as null, it's not possible to constract an empty JSON string ("").
to_json()
Internally, Oracle processes JSON data in the UTF-8 encoding.
dbms_json

JSON datatype

21c:
create table tq84_json( j json ); 
In 19c, the previous create table statement produces an ORA-00902: invalid datatype. It is, however, possible to somewhat mitigate the error:
create table tq84_json( j blob, check (j is json format oson) ); 

See also

Oracle 21c: The SQL*Plus setting jsonprint defines the maximum length that is displayed for JSON values. Compare with set long.
Date formats
Examples

Index