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.
Parameters
Input Settings
The source JSON document. The JSON document can come from any string expression, including attribute values and workspace parameters.
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 thePretty Print格式类型,该选项可用于控制器l 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 theLinearizeformatting type.
When this parameter is set toYes, 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 theRemove Empty Stringsoption, except that it applies to null values. When it is set toYes, 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 toYes格式化程序将删除任何或一个空对象rrays from the input JSON. This is applied recursively in conjunction with theRemove Empty StringsandRemove Null Valuesparameters. 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 toYes. For example, suppose the following JSON object is the input to the formatter, and both theRemove Empty StringsandRemove Null Valuesparameters are set toYes.
[
[],
{},
[ 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
- Error description
- Line number where the error occurred
- Column number where the error occurred
- Error type/severity
Note:List attributesare not accessible from the output schema in Workbench unless they are first processed using a transformer that operates on them, such asListExploderorListConcatenator. All list attribute transformers are displayed in the Contents pane of the Transformer Help underLists. Alternatively,AttributeExposercan 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, clickbeside the applicable parameter. For more information, seeTransformer Parameter Menu Options.
Transformer Categories
FME Licensing Level
FME Professional edition and above
Search FME Knowledge Center
Search for samples and information about this transformer on theFME Knowledge Center.