JSONENCODE
Sintassi
%%{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))
Scopo
La funzione SQL JSONENCODE restituisce il testo codificato in JSON di un testo normale, con i caratteri speciali sottoposti a escape secondo la rappresentazione JSON.
Vedi anche JSONDECODE e JSONELEMENT.
Parametri:
- Input (
ANY): l'input che verrà convertito dal proprio tipo in formato JSON.
Restituisce: un testo che rappresenta l'input codificato in formato JSON come varchar2. Un input null restituisce il letterale JSON null, sia che si tratti di una costante sia che si tratti del valore di una Colonna; pertanto, un testo JSON costruito tramite concatenazione rimane valido.
Esempi
L'esempio seguente recupera la rappresentazione JSON di un testo:
select jsonencode('Special characters such as backslash (\) and quote (").')
----------------
"Special characters such as backslash (\\) and quote (\")."
L'esempio seguente crea un oggetto JSON per ogni riga, anche per le righe prive di valore:
select '{"name": ' || jsonencode(v.name) || '}'
from ( select 'Invantive' name from dual@DataDictionary
union all
select null from dual@DataDictionary
) v
----------------
{"name": "Invantive"}
{"name": null}
L'esempio seguente recupera la rappresentazione JSON di una data/ora:
select jsonencode(sysdateutc)
----------------
"2026-06-09T11:14:32.4407146Z"