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.

fut_json_stringattributes

Description: With this attribute it is possible to make sure other attributes are treated as strings during conversion

Values: A semicolon separated list of attributes to be treated as string, e.g. "version;age"

Usage: It helps in determining the data type of the XML attribute'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.

fut_json_keep_namespaces (25.01+)

Description: This attribute can be used to determine if namespaces should be added in the JSON output as '@xmlns' items or should be omitted during conversion. This attribute has to be added in the root element of the XML structure to be used. In all other nodes, this attribute will be handled as any other attributes and will just be converted to JSON.

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

Usage: In some situations it might be needed to include the namespace in the JSON structure to include extra information that might be needed, for example when later converting back to XML.

fut_json_keep_table_attributes (25.01+)

Description: This attribute can be used to change the behavior of Futurama tables when converting to JSON. Futurama tables contain attributes 'index1' and 'idnex2'. Default these attributes will be removed during conversion to JSON. Using this attribute it is possible to change this behavior and keep these attributes in JSON.

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

Usage: In some situations when converting XML to JSON, the table attributes are needed to get some information about the table size and structure..

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: 2025-01-28