Search notes:

Oracle: JSON_OBJECT

select
   json_object (
      'num'  value  42,
      'txt'  value 'Hello world',
      'dat'  value  sysdate
  ) json_obj
from
   dual;
--
-- JSON_OBJ
-- ----------------------------------------------------------
-- {"num":42,"txt":"Hello world","dat":"2024-02-12T16:42:20"}

Hierarchical JSON documents

json_object and json_array can be used to created nested (hierarchical) JSON documents:
select
   json_object(
     'nums' value json_array(1, 2, 3, 4, 5),
     'obj'  value json_object
      (
         'id'   value  42,
         'txt'  value 'hello world'
      )
   ) json_obj
from
   dual;
--
-- JSON_OBJ
-- --------------------------------------------------------
-- {"nums":[1,2,3,4,5],"obj":{"id":42,"txt":"hello world"}}

Pretty printing result

The keyword pretty can be placed in front of the closing paranthesis which causes the result to be arguably prettier:
select
   json_object(
     'nums' value json_array(1, 2, 3, 4, 5),
     'obj'  value json_object
      (
         'id'   value  42,
         'txt'  value 'hello world'
      )
      PRETTY
   ) json_obj
from
   dual;
-- JSON_OBJ
-----------
-- {
--   "nums" :
--   [
--     1,
--     2,
--     3,
--     4,
--     5
--   ],
--   "obj" :
--   {
--     "id" : 42,
--     "txt" : "hello world"
--   }
-- }

See also

Oracle SQL/JSON
The jsn PL/SQL package

Index