Search

 

Module:Editor

Version: 23.09 +

Type: String

Category:Conversion

 

Description

The formula 'ConvertXmlToJSON' transforms XML data into JSON format. You can use this formula when you have XML data from a source, like a file or an XmlBuilder reference, and you want to convert it into a JSON format for easy processing or integration with JSON-based systems. This feature is handy when converting XML data into a JSON structure, as the resulting JSON format is the same structure as a webservice that returns JSON.

Parameters

XML:

The input XML element that you want to convert to JSON.

PrettyPrint:

This parameter can be True or False. It indicates whether you want the resulting JSON string to be pretty-printed with indentation. Default is false.(Please note that enabling this option only affects the visual presentation of the JSON within the Editor and won't alter the result of the formula when it is used in an application).

Attributes and namespaces

We are converting XML data with attributes into a structured JSON format. Attributes are retained as objects within JSON objects. Namespaces are removed during transformation.

Special attributes and values

There are specific attributes however, that will not be returned as objects in JSON, but that can be used to create specific situations in JSON. The list of attributes that can be used are listed below.

fut_json_emit_element

Description: This attribute controls whether the XML element should be emitted as part of the JSON output.

Values: It accepts a boolean value (true or false).

Usage: If set to false, the XML element will not be included in the JSON output. If set to true or not present, the XML element will be included.

fut_json_emit_array

Description: This attribute indicates whether the XML element should be emitted as a JSON array.

Values: It accepts a boolean value (true or false).

Usage: If set to true, the XML element and its child elements will be treated as an array in the JSON output. If set to false or not present, the XML element will be treated as a JSON object.

fut_json_datatype

Description: This attribute specifies the data type of the XML element's content.

Values: It accepts string value "string".

Usage: It helps in determining the data type of the XML element's content when converting it to JSON. It can be used when an element is of type boolean, long or double, but should be treated as a string.

__dollar__ transformation

Description: This can be set as XmlName when a dollar sign is needed in JSON.

Values: part of XmlName.

Usage: During XML-to-JSON conversion, all element names with __dollar__ will be replaced with a dollar sign. This ensures that the resulting JSON adheres to JSON naming conventions.

Example

Description

In the following example the formula 'ConvertXMLToJSON' is used to convert XML string to a JSON format.

Values parameters

Xml:

	
		Pension
		2019-05-20
		80000
		7.5
		true
		10
	
PrettyPrint:

True

JSON Result

{
	"PensionPlans": {
		"Plan": {
			"PlanType": "Pension",
			"PlanName": "Pension",
			"StartDate": "2019-05-20",
			"TotalContributions": {
				"Currency": "EUR",
				"value": 80000
			},
			"AverageAnnualReturn": 7.5,
			"IsFlexible": true,
			"YearsActive": "10"
		}
	}
}

Values parameters

Xml:

	
		1
	
	2
PrettyPrint:

False

JSON Result 2

{"b":[{"arrayItem":1}],"a":2}

Values parameters

Xml:

	<__dollar__example>https://dollarsign
PrettyPrint:

False

JSON Result 3

{"jsonschema":{"$example":"https://dollarsign"}}

Related Topics

ConvertJSONtoXml: To convert JSON to XML

FileSaver: To save JSON to a file

Feedback

If you have any questions about this subject or if you want to provide us feedback please send us an e-mail.

Updated: 2023-09-29