FME Transformers: 2024.1
FME Transformers: 2024.1
JSONFormatter
Provides options for formatting JSON (JavaScript Object Notation) text.
Configuration
Input Ports
Input
Input features that contain the JSON text attributes.
Output Ports
Output
Features output through this port will contain formatted JSON text.
<Rejected>
Features with an invalid JSON document are output through this port.
Parameters
Source
Input Source |
Allows for selecting between one of two options for JSON input: JSON Document or File/URL |
JSON Document |
If selected, The JSON document can come from any string expression, including attribute values and workspace parameters. |
File/URL |
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. |
Formatting
Formatting Type |
Select the desired formatting of the JSON text:
|
Indent Style |
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. |
Remove Empty Strings |
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" : [] } |
Remove Null Values |
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" } ] |
Remove Empty Objects and Arrays |
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 Attribute Names
Result Attribute |
Name the attribute to contain the formatted JSON text. |
Result Encoding |
Specifies the character encoding for the Result Attribute. Valid options are UTF-8, UTF-16 and UTF-32. |
List Attribute for Formatting Errors |
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:
Note List attributes are not accessible from the output schema in FME 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
Transformer parameters can be set by directly entering values, using expressions, or referencing other elements in the workspace such as attribute values or user parameters. Various editors and context menus are available to assist. To see what is available, click beside the applicable parameter.
How to Set Parameter Values
Defining Values
There are several ways to define a value for use in a Transformer. The simplest is to simply type in a value or string, which can include functions of various types such as attribute references, math and string functions, and workspace parameters.
Using the Text Editor
The Text Editor provides a convenient way to construct text strings (including regular expressions) from various data sources, such as attributes, parameters, and constants, where the result is used directly inside a parameter.
Using the Arithmetic Editor
The Arithmetic Editor provides a convenient way to construct math expressions from various data sources, such as attributes, parameters, and feature functions, where the result is used directly inside a parameter.
Conditional Values
Set values depending on one or more test conditions that either pass or fail.
Parameter Condition Definition Dialog
Content
Expressions and strings can include a number of functions, characters, parameters, and more.
When setting values - whether entered directly in a parameter or constructed using one of the editors - strings and expressions containing String, Math, Date/Time or FME Feature Functions will have those functions evaluated. Therefore, the names of these functions (in the form @<function_name>) should not be used as literal string values.
Content Types
These functions manipulate and format strings. | |
Special Characters |
A set of control characters is available in the Text Editor. |
Math functions are available in both editors. | |
Date/Time Functions | Date and time functions are available in the Text Editor. |
These operators are available in the Arithmetic Editor. | |
These return primarily feature-specific values. | |
FME and workspace-specific parameters may be used. | |
Creating and Modifying User Parameters | Create your own editable parameters. |
Dialog Options - Tables
Table Tools
Transformers with table-style parameters have additional tools for populating and manipulating values.
Row Reordering
|
Enabled once you have clicked on a row item. Choices include:
|
Cut, Copy, and Paste
|
Enabled once you have clicked on a row item. Choices include:
Cut, copy, and paste may be used within a transformer, or between transformers. |
Filter
|
Start typing a string, and the matrix will only display rows matching those characters. Searches all columns. This only affects the display of attributes within the transformer - it does not alter which attributes are output. |
Import
|
Import populates the table with a set of new attributes read from a dataset. Specific application varies between transformers. |
Reset/Refresh
|
Generally resets the table to its initial state, and may provide additional options to remove invalid entries. Behavior varies between transformers. |
Note: Not all tools are available in all transformers.
For more information, see Transformer Parameter Menu Options.
FME Community
The FME Community is the place for demos, how-tos, articles, FAQs, and more. Get answers to your questions, learn from other users, and suggest, vote, and comment on new features.
Search for all results about the JSONFormatter on the FME Community.