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.
为每个文档ument 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 anXQueryexpression, a JSON object or a JSON array.
The更新features provide the attribute values used in the document update operations.The文献feature is only used to supply the JSON document which is to be updated.
For each feature that enters the更新port, all of the update operations listed in the transformer will be applied to each feature that entered the transformer through the文献port.Therefore, no changes will be made to the JSON document if no features enter the transformer through the更新port.
Note that if the document is entered directly into the transformer parameters, it may be processed in two different ways:
- If no文献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文献port.
- If文献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.
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.
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文献input port.These features will contain the attributes values which are used in the document updates.
Output Ports
The文献input features will be output through this port.These features will contain the updated document, which will be stored in the attribute named in theResult Attributeparameter.The updated document will always be saved as a utf-8 encoded attribute value, regardless of the encoding of the original document.
Parameters
Transformer
This parameter is used to specify which update features will modify a document.When this parameter is set to a list of attributes,文献features will only be modified by更新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更新features with the same values for the “group by” attributes are provided to the transformer.
过程在结束(封闭): This is the default behavior.Processing will only occur in this transformer once all input is present.
过程当组更改(高级): This transformer will process input groups in order.Changes of the value of the Group By parameter on the input stream will trigger processing on the currently accumulating group.This may improve overall speed (particularly with multiple, equally-sized groups), but could cause undesired behavior if input groups are not truly ordered.
有使用两个典型原因过程当组更改(高级)。第一个是有意识地在组要被处理(并且已经如此命令)传入的数据。在这种情况下,结构使然集团通过使用 - 而不是性能方面的考虑。
第二个原因可能是潜在的性能提升。
性能提升是最有可能当数据已经排序(或使用阅读SQL ORDER BY声明),因为更少的工作需要FME的。如果数据需要排序,它可以在工作区中进行排序(虽然增加的处理开销可能会抵消任何收益)。
排序根据数据流的数目变得更困难。多个数据流可以几乎是不可能的排序到正确的顺序,因为所有的功能匹配通过...分组值需要到达之前的任何特征属于下一组(任何特征类型或数据集的)。在这种情况下,使用通过...分组同过程在结束(封闭)可能是等效的和简单的方法。
注意:多种要素类型和特点从多个数据集通常不会自然出现在正确的顺序。
如同许多情况下,在您的工作与你的数据测试不同的方法是确定性能提升的唯一准确的方法。
JSON Document
This parameter is used to specify the type of JSON document which is to be modified.JSON (Paramet可能来自输入功能er Value: Text or Attribute), or it may come from an external file.(Parameter Value: JSON File)
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.
When the JSON Input parameter is set to ‘JSON File’, this parameter is used to specify the location of the file.The file path may be entered directly into the parameter, or the path may come from an attribute value.
更新s
Each row in the Updates table specifies a single update operation.
This parameter specifies the type of modification to apply to the XML document.The possible updates are:
更新类型 | 描述 |
---|---|
插入对象 |
插入一个新的键/值对为对象。关键的名称从“对象/数组索引”塔中取出。所插入的值是从Value参数作出。 |
合并对象 |
副本从一个对象中的所有键/值对成另一种。如果Value参数不是JSON对象,或者XQuery表达式,其计算结果为对象,更新将失败。 |
插入阵列 |
插入一个新的值到一个数组,在指定的位置。阵列位置(其在0开始计数)从“对象/数组索引”列采取,并且应该是一个整数。新的值从值列拍摄。 |
追加数组 |
追加新的值到一个数组的末尾。 |
合并阵列 |
副本从一个阵列的所有值到另一个。如果Value参数不是JSON阵列,或XQuery表达式求值为阵列,更新将失败。 |
更换对象的价值 |
替换的对象项的值。密钥,其值是要被替换从“对象/阵列索引”参数取值。 |
替换数组值 |
在一个阵列中的指定位置替换值。替换值的数组索引从“对象/数组索引”塔取出。该指数应该是一个整数。阵列索引从0被计数。 |
重命名对象键 |
更改对象的键名。要重命名的关键是从“对象/数组索引”参数取值。 |
从对象中删除 |
除去来自物体的键/值对。要被去除的密钥是从“对象/阵列索引”参数取值。 |
从数组中删除 |
删除数组的值。的值,以除去所述的阵列索引从“对象/阵列索引”塔取出。该指数应该是一个整数。阵列索引从0被计数。 |
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.
An integer can be used to identify a position within an array:
- json[0] – If the root value is an array, this path refers to the first value in the array.If the root value is an object, this path will not resolve to any value.
- json[4] – If the root value is an array, this path refers to the fifth value in the array.
A quoted string can be used to refer to the value of an object key:
- json["location"] – If the root value is an object, this path refers to the value of the ‘location’ key in the object.If the root value is an array, this path will not resolve to any value.
- JSON [“特征”] - 指的根对象的“功能”键的值。
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.
- JSON [0] [“所在地”] - 此路径是指在根阵列中的第一个元素的“位置”对象密钥。
- JSON [“特征”] [0] [“位置”] - 此路径是指特征‘阵列的根对象的“中的第一个项目位置键’的值。例如,这可能适用于以下(不完全)文件:
{
“特征” : [
{ “位置” : { ...}}
]
}
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.
- JSON [*] - 如果根值是一个数组,该路径是指该阵列中的所有值。如果根值是一个对象,该路径是指在对象中的所有键的值。
- JSON [*] [“所在地”] - 此路径指的是根对象或阵列的所有子值的“位置”键。
- JSON [“特色”] [*] - 此路径是指所有的值包含在根对象的“功能”键的值。
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.
- JSON [@Value(指数)〕 - 此路径是指根段列阵的位置处的项指示由“索引”属性。
- JSON [“@值(键)”] - 此路径指的是对象值,其键在“key”属性被命名。
注意:The @Value() functions used in the path parameter will apply to the更新feature being processed, not the文献feature that is being updated
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.
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.
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 theJSONTemplatertransformer) could be entered as the parameter value.It would then be evaluated before being inserted into the document.
注意:Any FME XQuery functions used in the new value will access the更新feature, not the文献feature.
Parameters
This parameter specifies whether or not Workbench should try to validate the attribute names which are passed to any XQuery functions used in the Value column.
This parameter specifies the attribute to which the updated JSON document will be written.The default is_结果。
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
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 samples and information about this transformer on theFME Community。