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

JSONENCODE

Syntax

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

Purpose

The JSONENCODE SQL function returns the JSON encoded text of regular text, with the special characters according to the JSON representation escaped.

See also JSONDECODE and JSONELEMENT.

Parameters:

  • Input (ANY): the input which will be encoded from its type to JSON.

Returns: a text which is the input encoded to JSON as varchar2. A null input returns the JSON literal null, whether it is a constant or the value of a column, so a JSON text built by concatenation stays valid.

Examples

The following example retrieves the JSON representation of a text:

select jsonencode('Special characters such as backslash (\) and quote (").')

----------------
"Special characters such as backslash (\\) and quote (\")."

The following example builds a JSON object for every row, also for a row without a value:

select '{"name": ' || jsonencode(v.name) || '}'
from   ( select 'Invantive' name from dual@DataDictionary
         union all
         select null from dual@DataDictionary
       ) v

----------------
{"name": "Invantive"}
{"name": null}

The following example retrieves the JSON representation of a date/time:

select jsonencode(sysdateutc)

----------------
"2026-06-09T11:14:32.4407146Z"