Syntax FACTORY_DEF JSONQueryFactory [FACTORY_NAME ] [INPUT FEATURE_TYPE [ ]* []*]* MODE (EXTRACT|EXPLODE|FLATTEN) [EXPLODE_FORMAT (JSON|GEOJSON|ESRIJSON)] [EXTRACT_ATTR (YES|NO)] [RECURSIVE_FLATTEN (YES|NO)] JSON_ATTR [EXPLODE_QUERY ] [QUERIES [ ]+]* [OUTPUT (EVALUATED|EXPLODED|REJECTED) FEATURE_TYPE [ ]* []*]* Overview This factory uses JSON queries to extract values from JSON text stored in a feature attribute, or to convert JSON text into new features. The JSON_ATTR clause specifies the feature attribute that contains the JSON text, and the MODE clause specifies the factory's mode of operation. The EXPLODE_FORMAT clause specifies if the JSON text being converted is in plain JSON, GeoJSON, or ESRIJSON format. If it is in GeoJSON or ESRIJSON, then the exploded features will be treated as GeoJSON or ESRIJSON features that have attribute and geometry information. JSON Queries A JSON query is a simple mechanism to refer to values within a JSON document. A query is made up of one or more expressions, which are separated by a + operator. There are three types of expressions: JSON structure expressions, JSON property expressions and string literal expressions. JSON Structure Expressions A JSON structure expression can refer to values in a JSON document. The outermost JSON element, which must be an array or an object, is always referred to by the term json, and this term must appear at the beginning of every JSON structure expression. The child elements can be referred to using JavaScript-like square bracket index operators. For example, if the outermost element is an array, the first element of the array can be referred to by the expression json[0], the second element can be referred to by the expression json[1], and so on. Likewise, if the outermost JSON element is an object, with keys "name" and "address", then the values of these keys can be referred to by the expressions json["name"] and json["address"] respectively. These index operators can be cascaded. For example, it the outermost JSON element is an object with a key and "address" whose value is an object containing keys "city" and "province", then these values can be referred to by the expressions json["address"]["city"] and json["address"]["province"]. In order to refer to all of the values in an array or object, a wildcard index * can be used. For example, if the outermost JSON element is an array, then the expression json[*] refers to every element in the array. JSON Property Expressions A property expression is a structure expression as described above, followed by a . (dot) operator and a property name. Currently, the only supported properties are type and size. The type property returns the type of the JSON value referred to by the JSON structure expression. For example, if the outermost JSON element is an array, and the first element of the array is a string, then the expression json[0].type would have a value of string. The size property, which can only be applied to an array, returns the number of elements in the array. String Literal Expressions A string literal expression is simply a quoted string value, such as "this is a string literal expression". Extract Mode If the MODE caluse is set to EXTRACT, the factory will expect the value of the QUERIES clause to be a list of attributes and JSON queries (ie. attr1 query1 attr2 query2 .... ). For each input feature, the factory will then apply each query to the JSON text found in the value of the attribute identified by the JSON_ATTR clause, and populate the query's corresponding feature attribute with the value of the query. The factory will log an error and then ignore any query evaluation errors, rather than abort the translation. Explode Mode If the MODE clause is set to EXPLODE, the factory will expect the value of the EXPLODE_QUERY clause to be a valid JSON query, which only contains structure type expressions. For each input feature, the factory will then apply the query to the JSON text found in the value of the attribute identified by the JSON_ATTR clause. For each JSON value referred to by the query, the factory will create a new FME feature which will contain the JSON value in the attribute identified by the JSON_ATTR clause. EXPLODE_FORMAT specifies how the JSON text should be parsed. If it is set to 'JSON', the text will be treated as plain JSON text. If it is set to 'GEOJSON' or 'ESRIJSON', GeoJSON or ESRIJSON features will be constructed from the JSON text. If no valid GeoJSON or ESRIJSON features are constructed, a warning will be issued and the text will be treated as plain JSON. The EXTRACT_ATTR clause specifies whether or not the keys of a JSON Object should be added to the new FME feature as attributes. If EXTRACT_ATTR is set to 'Yes' and EXPLODE_FORMAT is 'GEOJSON' or 'ESRIJSON', no attributes will be constructed from keys that are valid GeoJSON or ESRIJSON keys, as these will be handled by the respective format parser. Each new FME feature produced from the JSON text contained by an input feature will contain a copy of all the attributes from the original input feature, as well as several new attributes. The attribute identified by the JSON_ATTR clause will contain the JSON text that the feature represents. The json_type attribute of the new feature will contain the type of JSON value that the new feature was constructed from, and the json_index attribute will contain the index (array location or object key) of the JSON value that the feature represents. The factory will log a warning, and then ignore any evaluation errors in the JSON query, rather than abort the translation. Output Tags The JSONQueryFactory supports the following output tags. EVALUATED When the factory is run in EXTRACT mode, the FME features containing the new attributes will be output through the EVALUATED output tag. EXPLODED When the factory is run in EXPLODE mode, the FME features containing the new attributes will be output through the EXPLODED output tag. REJECTED Features which produce errors may be output through this port. TO BE RESOLVED MODE FLATTEN and RECURSIVE_FLATTEN added to Syntax section above, but not documented.