Using Oracle 12.2
Goal: Convert XML data in a CLOB to JSON
Desire: Use built in functionality of Oracle (does it even exist?)
I'm under the impression that Oracle CAN convert the XML to JSON on it's own. However, I am unable to find a straight forward answer or example in SO or Google and have never done something like this so I'm really uncertain how to proceed.
In Python it is 2 lines of code but am trying to put this into a Procedure on Oracle.
I don't have any XSLT files. I say files because looking at some of the historical data in the system I'm seeing 4 different formats of XML used and stored.
Need to pull all of the XML data and push as JSON to another table for testing.
Tried making sense from:
- Oracle: Convert XML to JSON
- How can i convert xml to json in oracle?
- Is there is any xml to json parser that can be used in oracle query?
- https://odieweblog.wordpress.com/tag/xml-to-json/ (This appears that we would need to know all the elements but we don't because we don't have the XSLT for any of the formats provided where some element:values exist and some do not when empty)
- https://docs.oracle.com/cd/E65459_01/dev.1112/e65461/content/conversion_xml_to_json.html (What filter? Only thing I see in SQL Developer for filter is ALWAYS non selectable)
- https://docs.oracle.com/en/database/oracle/oracle-database/12.2/adjsn/changes.html#GUID-C14C52AA-E651-4E79-BA23-58957F498FBF
Any information would be greatly appreciated.
Updated sample xml to json
<elementA>
<firstName>snoopy</firstName>
<lastName>brown</lastName>
<favoriteNumbers>
<value>1</value>
<value>2</value>
<value>3</value>
</favoriteNumbers>
</elementA>
Expect direct translation
{
elementA:{
firstName:'snoopy',
lastName:'brown'
favoriteNumbers:{
value:[1,3,4]
]}
}
}