37.36 TO_XMLTYPE_SQL Function
This function parses a JSON-formatted varchar2
or CLOB
and converts it to an xmltype. This function overload has the p_strict
parameter as VARCHAR2
in order to allow invoking from within a SQL query and having JSON parsing in LAX mode.
Syntax
APEX_JSON.TO_XMLTYPE_SQL (
p_source IN VARCHAR2,
p_strict IN VARCHAR2 DEFAULT 'Y' )
RETURN sys.xmltype;
APEX_JSON.TO_XMLTYPE_SQL (
p_source IN CLOB,
p_strict IN VARCHAR2 DEFAULT 'Y' )
RETURN sys.xmltype;
Parameters
Parameter | Description |
---|---|
p_source |
The JSON source (VARCHAR2 or CLOB )
|
p_strict |
If Y (default), enforce strict JSON rules |
Returns
An xmltype representation of the json data
Example
This example SQL query converts JSON to XMLTYPE
and uses the XMLTABLE SQL
function to extract data. The p_strict
argument is set to N
, so the JSON can successfully be parsed in lax mode, although the items attribute is not enquoted.
select
attr_1
from
xmltable(
'/json/items/row'
passing apex_json.to_xmltype_sql( '{ items: [ 1, 2, { "foo": true } ] }', p_strict => 'N' )
columns
attr_1 varchar2(20) path 'foo/text()'
);
Parent topic: APEX_JSON