Skip to main content Skip to complementary content

Validating a JSON file 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

Using a JSON file lets you validate all data from the file. If one record is not validated against the schema, all records are considered invalid.

If you want to validate separate records and send each valid/invalid record to the dedicated output component, use raw input data. For more information, see Validating JSON schema using raw input data.

This scenario describes a Job which uses:
  • The tFileInputRaw component to use a JSON file as the input.
  • The tJSONValidator component to validate JSON columns.
  • The tLogRow component to output the results.
A Job using the tFileInputRaw, tJSONValidator, and two tLogRow components.

Setting up the Job

Procedure

  1. Drop the following components from the Palette onto the design workspace: tFileInputRaw, tJSONValidator and two tLogRow.
  2. Connect tFileInputRaw to tJSONValidator using a Main link.
  3. Connect tJSONValidator to one tLogRow using the FLOW link.
  4. Connect tJSONValidator to the other tLogRow using the Reject link.

Configuring the input component

Procedure

  1. Double-click tFileInputRaw to open its Basic settings view in the Component tab.
  2. Click Edit Schema.
  3. In the open dialog box, click the [+] button and add the columns that hold the initial input data.
    In this example, add one column named content, and select Object as Type.
  4. Click OK to close the dialog box.
  5. Select Read the file as a string.
  6. Select the encoding format from the drop-down list. In this example, ISO-8859-15.

Configuring the tJSONValidator component

Procedure

  1. Double-click tJSONValidator to display the Basic settings view and define the component properties.
  2. If required, click Sync columns to retrieve the schema defined in the input component.
  3. Click Add to add rows to the Allocate area.
  4. Select the input column from the drop-down list.
  5. Define the schema against which the data must be validated by entering the path to the schema file in double quotes.
    In this example, "inputSchema.json".
    Configuration of tJSONValidator
    Information noteNote: When the $schema dialect is not defined in the schema, define the JSON schema draft version in the Advanced settings.

Configuring the output component and executing the Job

Procedure

  1. Double-click the tLogRow components to display the Basic settings view.
  2. Select Table (print values in cells of a table) for both components.
  3. Press F6 to save the Job and execute it.

Results

The records are sent to one of the tLogRow components:
  • If all records are valid, they are sent through the FLOW link.
  • If at least one record is invalid, all records are sent through the Reject link.

Did this page help you?

If you find any issues with this page or its content – a typo, a missing step, or a technical error – please let us know!