
Component family |
Processing/Fields |
|
Function |
tExtractJSONFields extracts the |
|
Purpose |
tExtractJSONFields extracts the |
|
Basic settings |
Property type |
Either Built-in or Repository. |
|
|
Built-in: No property data is |
|
|
Repository: Select the repository |
Schema and Edit |
A schema is a row description, it defines the number of fields to Click Edit schema to make changes to the schema. If the
|
|
|
|
Built-in: The schema will be |
|
|
Repository: The schema already |
|
Read By |
Select a way of extracting the specified JSON field from the list, |
|
JSON field |
List of the JSON fields to be extracted. |
|
Loop XPath query |
Node within the JSON field, on which the loop is based. This field is available only when Xpath is selected from the Read By list. |
|
Loop Jsonpath query |
Specify the JSONPath node on which the loop is based. This field is available only when JsonPath is selected from the Read By list. |
|
Mapping |
Complete this table to map the columns defined in the schema to
|
|
Die on error |
Select this check box to stop the execution of the Job when an error occurs. Clear the check box to skip any rows on error and complete the process for error-free rows. This feature is not available to the Storm |
Advanced settings |
Encoding |
Select the encoding from the list or select Custom and |
tStatCatcher Statistics |
Select this check box to gather the Job processing metadata at a Note that this check box is not available in |
|
Global Variables |
ERROR_MESSAGE: the error message generated by the NB_LINE: the number of rows read by an input component or A Flow variable functions during the execution of a component while an After variable To fill up a field or expression with a variable, press Ctrl + For further information about variables, see Talend Studio |
|
Usage |
This component is an intermediate component. It needs an input and |
|
Usage in Map/Reduce Jobs |
If you have subscribed to one of the Talend solutions with Big Data, you can also You need to use the Hadoop Configuration tab in the For further information about a Talend Map/Reduce Job, see the sections Note that in this documentation, unless otherwise explicitly stated, a scenario presents |
|
Usage in Storm Jobs |
If you have subscribed to one of the Talend solutions with Big Data, you can also The Storm version does not support the use of the global variables. You need to use the Storm Configuration tab in the This connection is effective on a per-Job basis. For further information about a Talend Storm Job, see the sections Note that in this documentation, unless otherwise explicitly stated, a scenario presents |
|
Log4j |
The activity of this component can be logged using the log4j feature. For more information on this feature, see Talend Studio User For more information on the log4j logging levels, see the Apache documentation at http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/Level.html. |
|
Limitation |
Due to license incompatibility, one or more JARs required to use this component are not |
In this scenario, tWriteJSONField wraps the incoming
data into JSON fields, data of which is then extracted by tExtractJSONFields. Meanwhile, the error messages generated due to
extraction failure, which include the concerned JSON fields and errors, are retrieved
via a Row > Reject
link.
-
Drop the following components from the Palette onto the design workspace: tFixedFlowInput, tWriteJSONField, tExtractJSONFields, and tLogRow (X2). The two tLogRow components are renamed as data_extracted and reject_info.
-
Link tFixedFlowInput and tWriteJSONField using a Row > Main connection.
-
Link tWriteJSONField and tExtractJSONFields using a Row > Main connection.
-
Link tExtractJSONFields and data_extracted using a Row > Main connection.
-
Link tExtractJSONFields and reject_info using a Row > Reject connection.
Setting up the tFixedFlowInput
-
Double-click tFixedFlowInput to display
its Basic settings view. -
Click Edit schema to open the schema
editor.Click the [+] button to add three
columns, namely firstname, lastname and dept, with the type of string.Click OK to close the editor.
-
Select Use Inline Content and enter the
data below in the Content box:123Andrew;Wallace;DocJohn;Smith;R&DChristian;Dior;Sales
Setting up the tWriteJSONField
-
Click tWriteJSONField to display its
Basic settings view. -
Click Configure JSON Tree to open the XML
tree editor.The schema of tFixedFlowInput appears in
the Linker source panel. -
In the Linker target panel, click the
default rootTag and type in staff, which is the root node of the JSON field
to be generated. -
Right-click staff and select Add Sub-element from the context menu.
-
In the pop-up box, enter the sub-node name, namely firstname.
Repeat the steps to add two more sub-nodes, namely lastname and dept.
-
Right-click firstname and select
Set As Loop Element from the context
menu. -
Drop firstname from the Linker source panel to its counterpart in the
Linker target panel.In the pop-up dialog box, select Add linker to
target node.Click OK to close the dialog box.
-
Repeat the steps to link the two other items.
Click OK to close the XML tree
editor. -
Click Edit schema to open the schema
editor. -
Click the [+] button in the right panel
to add one column, namely staff, which
will hold the JSON data generated.Click OK to close the editor.
Setting up the tExtractJSONFields
-
Double-click tExtractJSONFields to
display its Basic settings view. -
Click Edit schema to open the schema
editor. -
Click the [+] button in the right panel
to add three columns, namely firstname,
lastname and dept, which will hold the data of their counterpart nodes in
the JSON field staff.Click OK to close the editor.
-
In the pop-up Propagate box, click
Yes to propagate the schema to the
subsequent components. -
In the Loop XPath query field, enter
“/staff”, which is the root node of
the JSON data. -
In the Mapping area, type in the node
name of the JSON data under the XPath query
part. The data of those nodes will be extracted and passed to their
counterpart columns defined in the output schema. -
Specifically, define the XPath query “firstname” for the column firstname, “lastname” for
the column lastname, and “” for the column dept. Note that “” is not
a valid XPath query and will lead to execution errors.
In this scenario, tFileInputJSON retrieves the
friends node from a JSON file that contains the
data of a Facebook user and tExtractJSONFields extracts
the data from the friends node for flat data
output.
-
Drop the following components from the Palette onto the design workspace: tFileInputJSON, tExtractJSONFields and tLogRow.
-
Link tFileInputJSON and tExtractJSONFields using a Row > Main connection.
-
Link tExtractJSONFields and tLogRow using a Row > Main connection.
-
Double-click tFileInputJSON to display
its Basic settings view. -
Click Edit schema to open the schema
editor.Click the [+] button to add one column,
namely friends, of the String
type.Click OK to close the editor.
-
Click the […] button to browse for the
JSON file, facebook.json in this
case:12345678910111213141516171819202122232425262728293031323334353637383940{ "user": { "id": "9999912398","name": "Kelly Clarkson","friends": [{ "name": "Tom Cruise","id": "55555555555555","likes": {"data": [{ "category": "Movie","name": "The Shawshank Redemption","id": "103636093053996","created_time": "2012-11-20T15:52:07+0000"},{ "category": "Community","name": "Positiveretribution","id": "471389562899413","created_time": "2012-12-16T21:13:26+0000"}]}},{ "name": "Tom Hanks","id": "88888888888888""likes": {"data": [{ "category": "Journalist","name": "Janelle Wang","id": "136009823148851","created_time": "2013-01-01T08:22:17+0000"},{ "category": "Tv show","name": "Now With Alex Wagner","id": "305948749433410","created_time": "2012-11-20T06:14:10+0000"}]}}]}} -
Clear the Read by XPath check box.
In the Mapping table, enter the JSONPath
query “$.user.friends[*]” next to the
friends column, retrieving the entire
friends node from the source
file. -
Double-click tExtractJSONFields to
display its Basic settings view. -
Click Edit schema to open the schema
editor. -
Click the [+] button in the right panel
to add five columns, namely id, name, like_id, like_name and
like_category, which will hold the
data of relevant nodes in the JSON field friends.Click OK to close the editor.
-
In the pop-up Propagate box, click
Yes to propagate the schema to the
subsequent components. -
In the Loop XPath query field, enter
“/likes/data”. -
In the Mapping area, type in the queries
of the JSON nodes in the XPath query
column. The data of those nodes will be extracted and passed to their
counterpart columns defined in the output schema. -
Specifically, define the XPath query “../../id” (querying the “/friends/id” node) for the column id, “../../name”
(querying the “/friends/name” node) for
the column name, “id” for the column like_id, “name” for the
column like_name, and “category” for the column like_category. -
Double-click tLogRow to display its
Basic settings view. -
Select Table (print values in cells of a
table) for a better display of the results.