Skip to content
Advertisement

Postgresql Convert SQL XML Coding to SQL JSON Coding

How to convert XML SQL Coding to JSON SQL Coding. Example:

Now how to convert this XMLELEMENT & XMLFOREST into JSON functions. Please help me. Do we have equivalent XMLELEMENT/XMLFOREST in JSON functions.

xml:

json:

Advertisement

Answer

These Postgresql functions
json_build_object(VARIADIC "any") and
jsonb_build_object(VARIADIC "any")
are semantically close to XMLELEMENT and very convenient for ‘embroidering‘ of whatever complex JSON you may need. Your query might look like this:

I do not think that there is a XMLFOREST equivalent however.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement