1

select xmlParserJson(column1) from table; and that will give xml data converted to json.

If offical oracle xml to json parse that will be recomended .

If not offical can you tell me the method to install and run xml parse . Thanks

Himanshu sharma
  • 7,487
  • 4
  • 42
  • 75

1 Answers1

2

can you tell me the method to install and run xml parse

SELECT XMLTYPE( your_xml_string )
FROM   DUAL

Will parse your XML.

If you want to extract the values then you can use XMLTABLE or XMLQUERY to get the values out of the XML.

will give xml data converted to json.

Parse the XML and extract the values using the above methods and then use the Oracle 12.2 functions JSON_ARRAY, JSON_OBJECT, JSON_ARRAYAGG and JSON_OBJECTAGG to create the JSON from the data.

How can i parse <xml><name>himanshu</name></xml> to be covert to json in oracle by these methods.

First, you can read the documentation and the examples in it and try it yourself. But you could try:

SELECT JSON_OBJECTAGG( id VALUE text )
FROM   XMLTABLE(
         '/xml/*'
         PASSING XMLTYPE( '<xml><name>himanshu</name></xml>')
         COLUMNS id   VARCHAR2(200) PATH './name()',
                 text VARCHAR2(200) PATH './text()'
       );

I'm not on an Oracle 12c system at the moment so it is untested.

MT0
  • 143,790
  • 11
  • 59
  • 117
  • How can i parse himanshu to be covert to json in oracle by these methods. @ MT0 . I have a xmlType field which have xml data and need to convert that to json . how can i do in oracle query in select statement ? – Himanshu sharma Jun 21 '17 at 09:45
  • see this question https://stackoverflow.com/questions/44672324/i-have-running-json-object-in-oracle-12-1-0-2-and-it-is-saying-error-why – Himanshu sharma Jun 21 '17 at 10:04