- 19 Jul 2024
- 5 Minutes to read
- Print
- DarkLight
Data Formatter
- Updated on 19 Jul 2024
- 5 Minutes to read
- Print
- DarkLight
The goal of this build is to provide Flows for JSON and XML formatting in Decisions.
Key Features
- The main Flow provides the ability to format and convert data to the specified format.
- The ability to properly format data based on data type, including DateTime fields, Objects, and Lists.
- Example Flows that demonstrate the creation of nested JSON and nested XML data.
- Individual Flows for JSON and XML conversion.
Considerations
- Data Formatter includes two example Flows that demonstrate how to create nested data fields.
- The Nested JSON Example Flow shows how to create nested JSON objects using the Convert Data to JSON Flow.
- The Nested XML Example Flow shows how to create nested XML objects using the Convert Data to XML Flow.
- Top Level Field Name should be specified for XML strings containing multiple fields.
- When specifying multiple fields (the list of Main Data Formatters contains more than one Formatter), all fields must be nested within a single field to obtain a valid XML string. To obtain a valid XML string in this case, a Top Level Field Name should be specified.
- For an example, see the Nested XML Example Flow.
- The IsList boolean denotes whether or not the values in the Main Data Formatter should be formatted as a list of values.
- If the IsList boolean is false but multiple values are specified, only the first value in the list will be used.
- If the IsList boolean is true and only a single value is specified, this single value will still be formatted as a list.
Main Flows
The key Flows in this build are listed below:
Run Data Formatter
This is the main Flow. It formats the provided values as either a JSON or XML string based on the specified format type. It takes in the Data Format Type, an optional Top Level Field Name, and a list of Main Data Formatters. The Flow outputs the formatted string.
Convert Data to JSON
This Flow converts the provided data into a compact JSON string. It takes in an optional Top Level Field Name and a list of Main Data Formatters. Each Main Data Formatter contains the value(s), type, and name for a single field. It also contains a boolean denoting if the provided values should be formatted as a list. If a Top Level Field Name is provided, these values will be treated as a nested object. The Flow outputs the formatted JSON string.
Convert Data to XML
This Flow converts the provided data into a compact XML string. It takes in an optional Top Level Field Name and a list of Main Data Formatters. Each Main Data Formatter contains the value(s), type, and name for a single field. It also contains a boolean denoting if the provided values should be formatted as a list. If a Top Level Field Name is provided, these values will be treated as a nested object. The Flow outputs the formatted XML string.
How to Use Data Formatter
Run Data Formatter
Instructions for the Run Data Formatter Flow are below. This Flow, as well as the Convert Data to JSON and Convert Data to XML Flows, can be inserted into existing projects or used independently. This Flow accepts the following inputs:
- Data Format Type: This field is an Enum Data Type used to specify whether the data should be formatted as JSON or XML.
- Main Data Formatter List: This list of Simple Flow Structures contains the values, type, and name for each specified data field. The user will need to provide the following information for each Main Data Formatter:
- Field Name: The name of a specific property or field. This value is a string.
- IsList: A boolean value denoting whether or not the specified values should be formatted as a list.
- Type: The JSON data type for the field and its specified values.
- Values: A list of values, as strings, that should be captured in the field.
- Top Level Field Name: The name of the field or property that all specified values should be nested under. This value is a string. This field is optional and can be left null but may need to be specified to create a valid XML string.
- The Flow outputs a string of formatted text based on the selected Data Format Type.
Convert Data to JSON/XML
The Convert Data to JSON and Convert Data to XML Flows format the provided data to a compact JSON or compact XML format. These Flows can be used independently or inserted into existing Decisions projects. Both Flows take in the following input fields:
- Main Data Formatter List: Each Main Data Formatter captures the information for a single data field. The user will need to provide the following information for each Main Data Formatter:
- Field Name: The name of specific property or field. This value is a string.
- IsList: A boolean value denoting whether or not the specified values should be formatted as a list.
- Type: The JSON data type for the field and its specified values.
- Values: A list of values, as strings, that should be captured in the field.
- Top Level Field Name: The name of the field or property that all specified values should be nested under. This value is a string. This field is optional and can be left null. However, it may need to be specified for XML strings to ensure that a valid string is created.
- The Flows output a formatted string for their specific format type.
Nested JSON Example
This sample Flow demonstrates how to use the Convert Data to JSON Flow to create nested JSON objects. It uses the Convert Data to JSON Flow twice. The first Subflow creates the internal fields for a JSON object. The second Subflow nests this object into a field alongside other data. It outputs a JSON string that contains a nested object. Since the JSON structure does require all fields to be nested under a single field, a Top Level Field Name is not specified for either Subflow.
Nested XML Example
This example Flow demonstrates how to use the Convert Data to XML Flow to create nested XML objects. It uses the Convert Date to XML Flow twice. The first Subflow creates the internal fields for an XML object. The second Subflow nests this object into a field alongside other data. To ensure that a valid XML string is created, all data must be captured under a single XML tag. As such, a Top Level Field Name is specified for the second Subflow.