JSONスキーマをインポート - 8.0

Talend Data Mapperユーザーガイド

Version
8.0
Language
日本語
Product
Talend Big Data Platform
Talend Data Fabric
Talend Data Management Platform
Talend Data Services Platform
Talend MDM Platform
Talend Real-Time Big Data Platform
Module
Talend Studio
Content
ジョブデザインと開発 > ジョブデザイン
Last publication date
2024-03-28

Talend Data Mapperを使用すると、JSONスキーマからJSONストラクチャーを作成できます。

JSONスキーマエレメントのサポートについては、JSONスキーマのサポートをご覧ください。

Talend Data MapperはJSONドキュメントの検証にJSONスキーマを使用しません。JSONスキーマは、JSONストラクチャーを作成するためのモデルとしてのみ使われます。たとえば、文字列が"maxLength": 15と定義されている場合、長さが15文字を超えてもエラーが返されません。

注: この機能は、Talendが提供するR2022-03以降のTalend Studioマンスリーアップデートをインストール済みである場合のみ利用できます。詳細は管理者にお問い合わせください。

始める前に

  • インポートするJSONスキーマファイルがあること。
  • 無視する必要のある参照を [Window] (ウィンドウ) > [Preferences] (環境設定) > [Mapping] (マッピング) > [Representations] (表記)[Reference blacklist] (参照のブラックリスト)に追加していること。詳細は、表記の環境設定をご覧ください。

このタスクについて

この例では、次のJSONスキーマを使用します:
{
    "$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"
						}
					}
				}
					
            }
        }
    }
}

手順

  1. [Data Mapper]タブで[Hierarchical Mapper] (階層マッパー)ノードを展開し、[Structures] (ストラクチャー)を右クリックします。
  2. [New] (新規) > [Structure] (ストラクチャー)をクリックします。
  3. ウィザードが開いたら、[Import a structure definition] (ストラクチャー定義をインポート)を選択して[Next] (次へ)をクリックします。
  4. インポートのタイプ(この例では[JSON Schema] (JSONスキーマ))を選択し、[Next] (次へ)をクリックします。
  5. 使用するファイルを選択します:
    • ワークスペースで既存のリソースを選択します。
    • ローカルファイルをインポートします。
    • このファイルにURLを入力します。
  6. [Next] (次へ)をクリックします。
  7. フォルダーを選択して新しいストラクチャーの名前を入力し、[Next] (次へ)をクリックします。
  8. [Finish] (終了)をクリックします。

タスクの結果

JSONストラクチャーはスキーマで指定されたすべてのエレメントで作成されます。このスキーマに従ってサンプルドキュメントをインポートすると、正しくハイライトされたエレメントが表示されます。この例で使用されたスキーマで次のサンプルをインポートできます:
{
   "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"
         }
      }
   ]
}
結果は次のようになります。