JSONUpdater
Modifies JSON documents by performing one or more actions:
- Inserting a new value into a JSON object or array
- Replacing an existing value in a JSON object or array
- Merging the contents of two JSON objects or arrays
- Removing a value from a JSON object or array
- Appending a value to a JSON array
- Renaming a key in a JSON object.
For each document update, a JSON path expression is used to identify the location of the JSON object or array which is to be modified. A second parameter names the specific object key or array index which is to be changed. Note that the path may refer to more than one item. If this is the case, all the items will be modified.
For modifications that replace existing items or insert new items, two parameters are given which specify the value to be added to the document. This value may be given as a simple text value, or it may be an XQuery expression, a JSON object or a JSON array.
The Update features provide the attribute values used in the document update operations. The Document feature is only used to supply the JSON document which is to be updated.
For each feature that enters the Update port, all of the update operations listed in the transformer will be applied to each feature that entered the transformer through the Document port. Therefore, no changes will be made to the JSON document if no features enter the transformer through the Update port.
Note that if the document is entered directly into the transformer parameters, it may be processed in two different ways:
- If no Document features are given to the transformer, a new feature will be created to store the document. Each of the updates will be applied to the document, and it will then be output through the Document port.
- If Document features are given to the transformer, each of the updates will be applied to the document, and these features will be output from the transformer.
Configuration
Input Ports
Input features contain the JSON documents to be modified. The documents can be contained in an attribute, entered directly into the transformer, or contained in a file referenced by an attribute value.
This port may be left unconnected if a filename and path is entered directly into the JSON File parameter, or if the JSON text to be updated is entered directly in the JSON Text parameter.
For each feature which enters this input port, each of the updates listed in the transformer will be executed on each document which entered via the Document input port. These features will contain the attributes values which are used in the document updates.
Output Ports
The Document input features will be output through this port. These features will contain the updated document, which will be stored in the attribute named in the Result Attribute parameter. The updated document will always be saved as a utf-8 encoded attribute value, regardless of the encoding of the original document.
Parameters
Group Update Features By |
This parameter is used to specify which update features will modify a document. When this parameter is set to a list of attributes, Document features will only be modified by Update features that share the same values for these attributes. The document will be modified by all of the update features with the same attribute values. Note that a document will not be updated if no Update features with the same values for the “group by” attributes are provided to the transformer. |
||||
Complete Groups |
Select the point in processing at which groups are processed:
Considerations for Using Group By
There are two typical reasons for using When Group Changes (Advanced) . The first is incoming data that is intended to be processed in groups (and is already so ordered). In this case, the structure dictates Group By usage - not performance considerations. The second possible reason is potential performance gains. Performance gains are most likely when the data is already sorted (or read using a SQL ORDER BY statement) since less work is required of FME. If the data needs ordering, it can be sorted in the workspace (though the added processing overhead may negate any gains). Sorting becomes more difficult according to the number of data streams. Multiple streams of data could be almost impossible to sort into the correct order, since all features matching a Group By value need to arrive before any features (of any feature type or dataset) belonging to the next group. In this case, using Group By with When All Features Received may be the equivalent and simpler approach. Note Multiple feature types and features from multiple datasets will not generally naturally occur in the correct order.
As with many scenarios, testing different approaches in your workspace with your data is the only definitive way to identify performance gains. |
JSON Input |
This parameter is used to specify the type of JSON document which is to be modified. The JSON may come from the input features (Parameter Value: Text or Attribute), or it may come from an external file. (Parameter Value: JSON File) |
JSON Text |
When the JSON Input parameter is set to ‘Text or Attribute’, this parameter is used to specify the JSON text. The parameter may be set to an attribute value, or the JSON document may be entered into the parameter directly. |
JSON File |
When the JSON Input parameter is set to ‘JSON File’, this parameter is used to specify the location of the file. The filename and path may be entered directly into the parameter, or may be provided as an attribute value. The attribute must be on an feature routed into the Document input port. |
Each row in the Updates table specifies a single update operation.
Update Type |
This parameter specifies the type of modification to apply to the XML document. The possible updates are:
|
||||||||||||||||||||||
JSON Path |
This parameter is used to identify the JSON object or array which is to be updated. For updates which modify a specific object key or array index, the key / index is identified using the ‘Object/Array Index’ parameter. JSON paths use a simple text syntax to trace a route through a JSON document, from the top level object or array, down to the object or array which is being modified. All JSON documents must have a single object or array as the root value. In a JSON path, this root value is identified by the ‘json’ keyword. Thus, every JSON path begins with this keyword. Square bracket syntax is used to identify each level of the path. To point to an object that is not a list, the path may be simply 'json'. An integer can be used to identify a position within an array:
A quoted string can be used to refer to the value of an object key:
These indices may be repeated, to have the path go deeper into the JSON document. It is important to know the structure of the document, so that the types of indices (object or array) are correct.
A wildcard may be used to refer to all elements of an array, or all values in an object. A * character is used to denote a wildcard.
In order to use an attribute value in a JSON path, the @Value FME function should be used. If the attribute value is an object key, the @Value function should be enclosed in quotes.
Note The @Value() functions used in the path parameter will apply to the Update feature being processed, not the Document feature that is being updated
|
||||||||||||||||||||||
Object/Array Index |
This parameter is used to specify the specific object key / array index whose value is to be inserted/removed/modified. For object updates, this value of this parameter should be a string, which will be interpreted as an object key. Quotes are NOT required around the string in this parameter. For array updates, the value of this parameter should be an integer. Note that array indices start at 0. |
||||||||||||||||||||||
Value Type |
This parameter is used to indicate how the value of the Value parameter should be interpreted. The effects of the different values of this parameter are explained in the description of the Value parameter. In general, this parameter should be set to Plain Text if the transformer is intended to insert text content into the document, while it should be set to JSON/XQuery if the transformer is intended to insert JSON objects or arrays into the document, or if the value is being produced through XQuery function calls. |
||||||||||||||||||||||
Value |
This parameter is used to specify the new values that should be inserted into the document. If the Value Type parameter is set to Plain Text, the contents of this parameter will be encoded for safe use in an XML document. That is, double quotes will be escaped as \", backslashes will be escaped as \\, and so on. If the Value Type parameter is set to JSON/XQuery, the contents of this parameter will be interpreted as an XQuery expression. This allows the insertion of JSON values elements into the document. Also, this allows the use of the FME XQuery functions. For example, a JSON Template (for example, from the JSONTemplater transformer) could be entered as the parameter value. It would then be evaluated before being inserted into the document. Note Any FME XQuery functions used in the new value will access the Update feature, not the Document feature.
|
Validate Attribute Names |
This parameter specifies whether or not FME Workbench should try to validate the attribute names which are passed to any XQuery functions used in the Value column. |
Result Attribute |
This parameter specifies the attribute to which the updated JSON document will be written. The default is _result. |
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.
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. There are a number of tools and shortcuts that can assist in constructing values, generally available from the drop-down context menu adjacent to the value field.
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.
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
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.
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 JSONUpdater on the FME Community.