Skip to main content Skip to complementary content

Importing a JSON Schema

Talend Data Mapper allows you to create a JSON structure from a JSON Schema.

For more information about the support of JSON Schema elements, see JSON Schema support.

Talend Data Mapper does not use JSON Schemas to validate JSON documents. They are only used as models to create JSON structures. For example, if a string is defined as "maxLength": 15, no error will be returned if the string exceeds 15 characters.

Before you begin

  • You have a JSON Schema file to import.
  • You have added any references that need to be ignored to the Reference blacklist in Window > Preferences > Mapping > Representations. For more information, see Representation preferences.

About this task

This example uses the following JSON Schema:
{
    "$id": "https://example.com/arrays.schema.json",
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "description": "A representation of a list of customers.",
    "type": "object",
    "properties": {
        "customers": {
            "type": "array",
            "items": {
                "$ref": "#/$defs/customer"
            }
        }
    },
    "$defs": {
        "customer": {
            "type": "object",
            "properties": {
                "LastName": {
                    "type": "string",
                    "description": "The customer's last name."
                },
                "firstName": {
                    "type": "string",
                    "description": "The customer's last name."
                },
				"address": {
					"type": "object",
					"description": "The customer's address.",
					"properties": {
						"street": {
							"type": "string"
						},
						"postCode": {
							"type": "integer"
						},
						"city": {
							"type": "string"
						},
						"state": {
							"type": "string"
						},
						"country": {
							"type": "string"
						}
					}
				}
					
            }
        }
    }
}

Procedure

  1. In the Data Mapper tab, expand the Hierarchical Mapper node and right-click Structures.
  2. Click New > Structure.
  3. In the wizard that opens, select Import a structure definition and click Next.
  4. Select the type of import, JSON Schema in this example, and click Next.
  5. Select the file to use:
    • Select an existing resource in your workspace.
    • Import a local file.
    • Enter the URL to the file.
  6. Click Next.
  7. Select a folder and enter a name for your structure, then click Next.
  8. Click Finish.

Results

A JSON structure is created with all the elements specified in the schema. If you import a sample document following this schema, you can see the elements highlighted correctly. With the schema used in this example, you can import the following sample:
{
   "customers":[
      {
         "lastName":"Smith",
         "firstName":"Jane",
         "address":{
            "street":"4876 Felosa Drive",
            "postCode":90017,
            "city":"Los Angeles",
            "state":"CA",
            "country":"United States"
         }
      },
	  {
         "lastName":"Doe",
         "firstName":"John",
         "address":{
            "street":"4862 Parkway Street",
            "postCode":92203,
            "city":"Bermuda Dunes",
            "state":"CA",
            "country":"United States"
         }
      }
   ]
}
The result looks like this:

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!