JSONFormatter
Provides options for formatting JSON (JavaScript Object Notation) text.
Input Ports
Input features that contain the JSON text attributes.
Output Ports
Features output through this port will contain formatted JSON text.
Features with an invalid JSON document are output through this port.
Parameters
Source
Allows for selecting between one of two options for JSON input: JSON Document or File/URL
If selected, The JSON document can come from any string expression, including attribute values and workspace parameters.
If selected, the JSON source can be read from a local file at a specified file path, or from the internet at a specified URL.
Format Settings
Select the desired formatting of the JSON text:
- Pretty Print: The JSON text will be formatted by adding indentations and new lines for improved readability.
- Linearize: All JSON contents will be put on a single line, to reduce the size of the JSON text.
When using the Pretty Print formatting type, this option may be used to control the indent style of the formatted JSON text. Each indent may be a tab or 1-8 space characters. This parameter is disabled when using the Linearize formatting type.
When this parameter is set to Yes, the formatter will remove any empty string values. It will not remove strings which contain only whitespace. If the empty string is an object value, the associated object key will also be removed. Empty strings which are object keys will not be removed. For example, suppose the following object is the input JSON:
{
"key1" : "",
"key2" : " ",
"key3" : [""]
}
The output from the transformer will be:
{
"key2" : " ",
"key3" : []
}
This option is similar to the Remove Empty Strings option, except that it applies to null values. When it is set to Yes, the formatter will remove any nulls in the input JSON. If the null is an object value, the associated object key will also be removed. For example, suppose the following array is the input JSON:
[
null,
{
"key1" : null,
"key2" : "a value"
}
]
The output from the transformer will be:
[
{
"key2" : "a value"
}
]
When this parameter is set to Yes, the formatter will remove any empty objects or arrays from the input JSON. This is applied recursively in conjunction with the Remove Empty Strings and Remove Null Values parameters. That is, if empty strings, null values or nested empty objects or arrays cause an object or array to become empty, it will be removed. The root object or array will not be removed, so it is possible that the output from the formatter will be an empty object or array even if this parameter is set to Yes. For example, suppose the following JSON object is the input to the formatter, and both the Remove Empty Strings and Remove Null Values parameters are set to Yes.
[
[],
{},
[ null, "" ],
{
"key1" : "",
"key2" : null,
"key3" : []
}
]
The output from the formatter will be:
[]
Output Settings
Specifies the attribute which will contain the formatted JSON text.
Specifies the character encoding for the result attribute. Valid options are UTF-8, UTF-16 and UTF-32.
Name of the list attribute that contains information on JSON validation errors. The features that exit the transformer through the <Rejected> output port will have validation errors listed in this list attribute. Each validation error message is made up of four parts:
- Error description
- Line number where the error occurred
- Column number where the error occurred
- Error type/severity
Note: List attributes are not accessible from the output schema in Workbench unless they are first processed using a transformer that operates on them, such as ListExploder or ListConcatenator. Alternatively, AttributeExposer can be used.
Editing Transformer Parameters
Using a set of menu options, transformer parameters can be assigned by referencing other elements in the workspace. More advanced functions, such as an advanced editor and an arithmetic editor, are also available in some transformers. To access a menu of these options, click beside the applicable parameter. For more information, see Transformer Parameter Menu Options.
Transformer Categories
FME Licensing Level
FME Professional edition and above
Search FME Community
Search for samples and information about this transformer on the FME Community.