15.29 TO_XMLTYPE Function

This procedure parses a JSON-formatted varchar2 or CLOB and converts it to an xmltype.

Syntax

APEX_JSON.TO_XMLTYPE (
    p_source   IN VARCHAR2,
    p_strict   IN BOOLEAN DEFAULT TRUE )
RETURN sys.xmltype;

APEX_JSON.TO_XMLTYPE (
    p_source   IN CLOB,
    p_strict   IN BOOLEAN DEFAULT TRUE )
RETURN sys.xmltype;

Parameters

Table 15-35 TO_XMLTYPE Function Parameters

Parameter Description

p_source

The JSON source (VARCHAR2 or CLOB)

p_strict

If TRUE (default), enforce strict JSON rules

Returns

Table 15-36 TO_XMLTYPE Function Returns

Return Description

sys.xmltype

An xmltype representation of the JSON data.

Example

This example parses JSON and prints the XML representation.

DECLARE
    l_xml xmltype;
BEGIN
    l_xml := apex_json.to_xmltype('{ "items": [ 1, 2, { "foo": true } ] }');
    dbms_output.put_line(l_xml.getstringval);
END;