invantive documentationpart of invantive cloud
Invantive Support ForumsLog In / Sign Up

JSONELEMENT

Syntax

%%{init: {
  'theme': 'base',
  'flowchart': { 'padding': '7', 'nodeSpacing': '20', 'rankSpacing': '20' },
  'themeVariables': {
    'fontSize': '11px',
    'fontFamily': 'Arial'
  }
}}%%
flowchart LR
    Start((START)) --> JSONELEMENT[JSONELEMENT]:::quoted
    JSONELEMENT --> End((END))

Purpose

The JSONELEMENT SQL function returns the text as a JSON value assignment, with the JSON representation of special characters replaced by their original meaning.

See also JSONDECODE and JSONENCODE.

Parameters:

  • Name (varchar2): the name of the JSON element.
  • Input (ANY): the input which will be encoded to a JSON value.
  • Empty on Null (optional, boolean): true returns null for a null input, false returns the assignment with the JSON literal null. Defaults to true. A constant and the value of a column give the same result.

Returns: a text which is the input encoded as a JSON value assignment as varchar2.

Examples

The following example retrieves the text representation of a JSON value assignment for a guid:

select jsonelement('id', newid())

----------------
"id": "509951c7-6f95-4c8b-808e-a47b8b0739e1"

The following example retrieves the text representation of a JSON value assignment for a datetime:

select jsonelement('date', trunc(sysdateutc, -2))

----------------
"date": "2026-01-01T00:00:00Z"

The following example retrieves the text representation of a JSON value assignment for a varchar2:

select jsonelement('name', null, false)

----------------
"name": null