Validating raw input JSON data using a JSON schema
You can validate JSON columns using the tJSONValidator component.
This scenario applies only to Talend Data Integration, Talend Data Management Platform, Talend Big Data Platform, Talend Real-Time Big Data Platform, Talend MDM Platform, Talend Data Services Platform, Talend MDM Platform and Talend Data Fabric.
Information noteNote: The tJSONValidator component is available only if you have installed
the R2024-11 Talend Studio Monthly
update or a later one delivered by Talend. For
more information, check with your administrator.
About this task
If you want to validate all records and consider them all valid or invalid, use a JSON file. For more information, see Validating JSON schema using a JSON file.
This scenario describes a Job which uses:
- The tFixedFlowInput component to use raw data input.
- The tJSONValidator component to validate JSON columns.
- The tLogRow component to output the results.
Setting up the Job
Procedure
- Drop the following components from the Palette onto the design workspace: tFixedFlowInput, tJSONValidator and two tLogRow.
- Connect tFixedFlowInput to tJSONValidator using a Main link.
- Connect tJSONValidator to one tLogRow using the FLOW link.
- Connect tJSONValidator to the other tLogRow using the Reject link.
Configuring the input component
Procedure
Configuring the tJSONValidator component
Procedure
Configuring the output component and executing the Job
Procedure
- Double-click the tLogRow components to display the Basic settings view.
- Select Table (print values in cells of a table) for both components.
- Press F6 to save the Job and execute it.
Results
.--+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------.
| tLogRow_3(OK) |
|=-+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------=|
|id|jsonValue |
|=-+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------=|
|1 |{"customers":[{"lastName":"Smith","firstName":"Jane","address":{"street":"4876 Felosa Drive","postCode":90017,"city":"Los Angeles","state":"CA","country":"United States"}}]}|
|2 |{"customers":[{"lastName":"Doe","firstName":"John","address":{"street":"42373 Tenmile","postCode":92203,"city":"Bermuda Dunes","state":"CA","country":"United States"}}]} |
|5 |{"customers":[{"lastName":"Ming","firstName":"Li","address":{"street":"321 Da Bei Yao","postCode":10012,"city":"Bei Jing","state":"","country":"China"}}]} |
'--+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------'
.--+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.
| tLogRow_4(NOK) |
|=-+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------=|
|id|jsonValue |ExecutionResult |
|=-+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------=|
|3 |{"customers":[{"lastName":"Frye","firstName":"Lucy","address":{"street":"4862 Parkway Street","postCode":"92298","city":"Bermuda Dunes","state":"CA","country":"United States"}}]}|{"ExecutionResult":{"Status":"Invalid","Validations":[{"ColumnName":"jsonValue","Violations":[{"SchemaLocation":"https://example.com/arrays.schema.json#/$defs/customer/properties/address/properties/postCode/type","ErrorCode":"1029","ErrorType":"type","ErrorMessage":"$.customers[0].address.postCode: string found, integer expected","ElementValue":"92298","ElementLocation":"$.customers[0].address.postCode"}],"SchemaURI":"C:/inputSchema.json"}]}}|
|4 |{"customers":[{"lastName":"Joney","firstName":"Seb","address":{"street":"386 Hart Country Lane","postCode":30830,"city":"Waynesboro","state":8,"country":"United States"}}]} |{"ExecutionResult":{"Status":"Invalid","Validations":[{"ColumnName":"jsonValue","Violations":[{"SchemaLocation":"https://example.com/arrays.schema.json#/$defs/customer/properties/address/properties/state/type","ErrorCode":"1029","ErrorType":"type","ErrorMessage":"$.customers[0].address.state: integer found, string expected","ElementLocation":"$.customers[0].address.state"}],"SchemaURI":"C:/inputSchema.json"}]}} |
'--+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------'