Skip to content

json2xml

json2xml(json)

Description

Returns XML for given JSON string

Examples

Call or Deploy json2xml ?
Call json2xml directly

The easiest way to use bigfunctions

  • json2xml function is deployed in 39 public datasets for all of the 39 BigQuery regions.
  • It can be called by anyone. Just copy / paste examples below in your BigQuery console. It just works!
  • (You need to use the dataset in the same region as your datasets otherwise you may have a function not found error)

Public BigFunctions Datasets

Region Dataset
eu bigfunctions.eu
us bigfunctions.us
europe-west1 bigfunctions.europe_west1
asia-east1 bigfunctions.asia_east1
... ...
Deploy json2xml in your project

Why deploy?

  • You may prefer to deploy json2xml in your own project to build and manage your own catalog of functions.
  • This is particularly useful if you want to create private functions (for example calling your internal APIs).
  • Get started by reading the framework page

Deployment

json2xml function can be deployed with:

pip install bigfunctions
bigfun get json2xml
bigfun deploy json2xml

1. With valid JSON

select bigfunctions.eu.json2xml("{\"a\": {\"b\": \"foo\"}}")
select bigfunctions.us.json2xml("{\"a\": {\"b\": \"foo\"}}")
select bigfunctions.europe_west1.json2xml("{\"a\": {\"b\": \"foo\"}}")
+-------------------+
| xml               |
+-------------------+
| <a><b>foo</b></a> |
+-------------------+

2. With valid JSON and with one key that has empty string as a value

select bigfunctions.eu.json2xml("{\"a\": \"\"}")
select bigfunctions.us.json2xml("{\"a\": \"\"}")
select bigfunctions.europe_west1.json2xml("{\"a\": \"\"}")
+---------+
| xml     |
+---------+
| <a></a> |
+---------+

3. With invalid JSON

select bigfunctions.eu.json2xml("{\"a\": ")
select bigfunctions.us.json2xml("{\"a\": ")
select bigfunctions.europe_west1.json2xml("{\"a\": ")
+------+
| xml  |
+------+
| null |
+------+

Need help or Found a bug using json2xml?
Get help using json2xml

The community can help! Engage the conversation on Slack

We also provide professional suppport.

Report a bug about json2xml

If the function does not work as expected, please

  • report a bug so that it can be improved.
  • or open the discussion with the community on Slack.

We also provide professional suppport.

Use cases

A practical use case for the json2xml function is converting JSON data stored in BigQuery into an XML format for integration with systems that primarily use XML.

Scenario: You have product data stored in BigQuery in JSON format. A legacy system or a third-party partner requires product data in XML format for processing or integration.

Example:

Imagine your BigQuery table product_data has a column product_info containing JSON data like this:

{"product_id": "12345", "name": "Awesome Gadget", "price": 99.99, "description": "A really cool gadget."}

You can use the json2xml function to convert this JSON data to XML within your BigQuery query:

SELECT bigfunctions.us.json2xml(product_info) AS product_xml
FROM `your_project.your_dataset.product_data`;

This query will produce XML output like this:

<product_info><product_id>12345</product_id><name>Awesome Gadget</name><price>99.99</price><description>A really cool gadget.</description></product_info>

You can then export this XML data from BigQuery for use in the target system.

Other Use Cases:

  • Data Transformation for API Integration: Convert JSON responses from APIs to XML for consumption by services that expect XML.
  • Generating XML Reports: Transform JSON data into structured XML reports for specific business needs.
  • Data Migration: Migrate data stored in JSON format to systems that use XML.
  • Interoperability between Systems: Facilitate data exchange between systems that use different data formats (JSON and XML).

By using json2xml directly within BigQuery, you avoid the need to export the JSON data and process it externally, simplifying the data transformation process and improving efficiency.

Spread the word!

BigFunctions is fully open-source. Help make it a success by spreading the word!

Share on Add a on