Skip to main content

JSON to XML

Abstract

JSON to XML

DescriptionJSON to XML (uv-t-jsonToXml):

Converts JSON data (e.g. responses to REST services) to XML, so that it can be further processed, e.g., by XSLT.

Configuration Parameters

Name

Description

URL Prefix

Param which automatically replaces the defined URL with a whitespace

Inputs and Outputs

Name

Type

DataUnit

Description

Required

input

i

FilesDataUnit

Input JSON files

(tick)

output

o

FilesDataUnit

Produced XML data

(tick)
ExamplesPerform an API Request to PoolParty and Transform the JSON Response Into XML

The following image shows a pipeline which performs an API request to PoolParty, transforms the JSON response to XML, and converts this XML into RDF/XML.

24576307.png

The configuration of the DPU can be seen in the image below.

24576309.png

The URL Prefix allows you to automatically replace a part of text/URL with a whitespace. This is useful when you work with custom attributes URLs as when these are converted to XML format the first slash from http:/ will then break in the text causing an output of unwanted XML data.

e.g.

JSON Response

{
 "uri": "http://vocabulary.semantic-web.at/cocktails/0bbdca98-077b-48d1-99d6-47eca59c442c",
 "prefLabel": "Aviation",
 "http://vocabulary.semantic-web.at/cocktail-ontology/image": [
     "https://upload.wikimedia.org/wikipedia/commons/4/4f/Aviation_Cocktail.jpg"
 ]
}

Unwanted XML Output

<root>
  <http:>https://upload.wikimedia.org/wikipedia/commons/4/4f/Aviation_Cocktail.jpg</http:>
</root>

This is unwanted and is difficult to further transform due to the nature of needing to encode character breaks to handle this cause.

With the usage of the URL Prefix field we are able to have a better generated XML tag.

e.g.

Wanted XML Output

<root>
  <image>https://upload.wikimedia.org/wikipedia/commons/4/4f/Aviation_Cocktail.jpg</image>
</root>