XML-to-JSON Transformation

If the YQL results are in JSON format, and the table is backed by an XML data source, then YQL transforms the data from XML to JSON. This transformation is "lossy," that is, you cannot transform the JSON back to XML. YQL transforms XML data to JSON according to the following rules:

  • Attributes are mapped to name:value pairs.
  • Element CDATA or text sections are mapped to "content":value pairs if the element contains attributes or sub-elements. Otherwise they are mapped to the element name's value directly.
  • Namespace prefixes are removed from names.
  • If the attribute, element, or namespace-less element would result in the same key name in the JSON structure, an array is created instead.

For example, consider the following XML:

This XML is transformed to the following JSON structure:

Table of Contents