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
In the Data Mapper tab, expand the
Hierarchical Mapper node and right-click
Structures.
Click New > Structure.
In the wizard that opens, select Import a structure definition and click Next.
Select the type of import, JSON Schema in this example, and
click Next.
Select the file to use:
Select an existing resource in your workspace.
Import a local file.
Enter the URL to the file.
Click Next.
Select a folder and enter a name for your structure, then click
Next.
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: