このページでは、JSONスキーマを最大限に活用するためのさまざまなユースケースを示す例を紹介します。これらの例は、幅広いシナリオをカバーしており、各例にはJSONデータと説明が付いています。JSONスキーマがさまざまなドメインにどのように適用できるかを示しています。これらの例は、特定のニーズに合わせて変更できます。これはJSONスキーマを利用できる多くの方法の1つにすぎません。
住所
住所を表すスキーマで、さまざまな住所コンポーネントのオプションプロパティがあり、locality
、region
、countryName
が必須であることを強制し、postOfficeBox
またはextendedAddress
が提供されている場合は、streetAddress
も提供する必要があることを強制します。

スキーマ
{ "$id": "https://example.com/address.schema.json", "$schema": "https://json-schema.dokyumento.jp/draft/2020-12/schema", "description": "An address similar to http://microformats.org/wiki/h-card", "type": "object", "properties": { "postOfficeBox": { "type": "string" }, "extendedAddress": { "type": "string" }, "streetAddress": { "type": "string" }, "locality": { "type": "string" }, "region": { "type": "string" }, "postalCode": { "type": "string" }, "countryName": { "type": "string" } }, "required": [ "locality", "region", "countryName" ], "dependentRequired": { "postOfficeBox": [ "streetAddress" ], "extendedAddress": [ "streetAddress" ] }}
データ
{ "postOfficeBox": "123", "streetAddress": "456 Main St", "locality": "Cityville", "region": "State", "postalCode": "12345", "countryName": "Country"}
ブログ投稿
これは、ブログ記事を表すスキーマであり、title
、content
、publishedDate
、
スキーマ
{ "$id": "https://example.com/blog-post.schema.json", "$schema": "https://json-schema.dokyumento.jp/draft/2020-12/schema", "description": "A representation of a blog post", "type": "object", "required": ["title", "content", "author"], "properties": { "title": { "type": "string" }, "content": { "type": "string" }, "publishedDate": { "type": "string", "format": "date-time" }, "author": { "$ref": "https://example.com/user-profile.schema.json" }, "tags": { "type": "array", "items": { "type": "string" } } }}
データ
{ "title": "New Blog Post", "content": "This is the content of the blog post...", "publishedDate": "2023-08-25T15:00:00Z", "author": { "username": "authoruser", "email": "[email protected]" }, "tags": ["Technology", "Programming"]} カレンダー

スキーマ
{ "$id": "https://example.com/calendar.schema.json", "$schema": "https://json-schema.dokyumento.jp/draft/2020-12/schema", "description": "A representation of an event", "type": "object", "required": [ "dtstart", "summary" ], "properties": { "startDate": { "type": "string", "description": "Event starting time" }, "endDate": { "type": "string", "description": "Event ending time" }, "summary": { "type": "string" }, "location": { "type": "string" }, "url": { "type": "string" }, "duration": { "type": "string", "description": "Event duration" }, "recurrenceDate": { "type": "string", "description": "Recurrence date" }, "recurrenceDule": { "type": "string", "description": "Recurrence rule" }, "category": { "type": "string" }, "description": { "type": "string" }, "geo": { "$ref": "https://example.com/geographical-location.schema.json" } }}
データ
{ "startDate": "2023-08-25T10:00:00Z", "endDate": "2023-08-25T12:00:00Z", "summary": "Conference Presentation", "location": "Conference Center", "recurrenceDule": "FREQ=DAILY;COUNT=5"}
デバイスタイプ
{ "$id": "https://example.com/device.schema.json", "$schema": "https://json-schema.dokyumento.jp/draft/2020-12/schema", "type": "object", "properties": { "deviceType": { "type": "string" } }, "required": ["deviceType"], "oneOf": [ { "properties": { "deviceType": { "const": "smartphone" } }, "$ref": "https://example.com/smartphone.schema.json" }, { "properties": { "deviceType": { "const": "laptop" } }, "$ref": "https://example.com/laptop.schema.json" } ]}
{ "$id": "https://example.com/smartphone.schema.json", "$schema": "https://json-schema.dokyumento.jp/draft/2020-12/schema", "type": "object", "properties": { "brand": { "type": "string" }, "model": { "type": "string" }, "screenSize": { "type": "number" } }, "required": ["brand", "model", "screenSize"]}
{ "$id": "https://example.com/laptop.schema.json", "$schema": "https://json-schema.dokyumento.jp/draft/2020-12/schema", "type": "object", "properties": { "brand": { "type": "string" }, "model": { "type": "string" }, "processor": { "type": "string" }, "ramSize": { "type": "number" } }, "required": ["brand", "model", "processor", "ramSize"]}
データ
{ "deviceType": "smartphone", "brand": "Samsung", "model": "Galaxy S21", "screenSize": 6.2}
eコマースシステム

スキーマ
{ "$id": "https://example.com/ecommerce.schema.json", "$schema": "https://json-schema.dokyumento.jp/draft/2020-12/schema", "$defs": { "product": { "$anchor": "ProductSchema", "type": "object", "properties": { "name": { "type": "string" }, "price": { "type": "number", "minimum": 0 } } }, "order": { "$anchor": "OrderSchema", "type": "object", "properties": { "orderId": { "type": "string" }, "items": { "type": "array", "items": { "$ref": "#ProductSchema" } } } } }}
データ
{ "order": { "orderId": "ORD123", "items": [ { "name": "Product A", "price": 50 }, { "name": "Product B", "price": 30 } ] }}
地理的な場所
指定された範囲内のlatitude
(緯度)とlongitude
(経度)の値を持つ地理座標を表すスキーマ。

スキーマ
{ "$id": "https://example.com/geographical-location.schema.json", "$schema": "https://json-schema.dokyumento.jp/draft/2020-12/schema", "title": "Longitude and Latitude Values", "description": "A geographical coordinate.", "required": [ "latitude", "longitude" ], "type": "object", "properties": { "latitude": { "type": "number", "minimum": -90, "maximum": 90 }, "longitude": { "type": "number", "minimum": -180, "maximum": 180 } }}
データ
{ "latitude": 48.858093, "longitude": 2.294694}
健康記録
patientName
(患者名)、dateOfBirth
(生年月日)、bloodType
(血液型)、allergies
(アレルギー)、conditions
(既往歴)、medications
(服用薬)、emergencyContact
(緊急連絡先)を含む健康記録を表すスキーマ。

スキーマ
{ "$id": "https://example.com/health-record.schema.json", "$schema": "https://json-schema.dokyumento.jp/draft/2020-12/schema", "description": "Schema for representing a health record", "type": "object", "required": ["patientName", "dateOfBirth", "bloodType"], "properties": { "patientName": { "type": "string" }, "dateOfBirth": { "type": "string", "format": "date" }, "bloodType": { "type": "string" }, "allergies": { "type": "array", "items": { "type": "string" } }, "conditions": { "type": "array", "items": { "type": "string" } }, "medications": { "type": "array", "items": { "type": "string" } }, "emergencyContact": { "$ref": "https://example.com/user-profile.schema.json" } }}
データ
{ "patientName": "Jane Doe", "dateOfBirth": "1985-02-15", "bloodType": "A+", "allergies": ["Pollen", "Penicillin"], "conditions": ["Hypertension", "Diabetes"], "medications": ["Lisinopril", "Metformin"], "emergencyContact": { "username": "emergencyuser", "email": "[email protected]" }} 求人情報
これは、title
、company
、location
、description
、employmentType
、salary
、applicationDeadline
のようなプロパティを含む求人情報を表すスキーマです。また、アンカーを定義するために$anchor
キーワードを使用しています。

スキーマ
{ "$id": "https://example.com/job-posting.schema.json", "$schema": "https://json-schema.dokyumento.jp/draft/2020-12/schema", "description": "A representation of a job posting", "type": "object", "required": ["title", "company", "location", "description"], "properties": { "title": { "type": "string" }, "company": { "type": "string" }, "location": { "type": "string" }, "description": { "type": "string" }, "employmentType": { "type": "string" }, "salary": { "type": "number", "minimum": 0 }, "applicationDeadline": { "type": "string", "format": "date" } }}
データ
{ "title": "ソフトウェアエンジニア", "company": "Tech Solutions Inc.", "location": "シティビル", "description": "ソフトウェアエンジニアとして私たちのチームに参加しませんか...", "employmentType": "フルタイム", "salary": 80000, "applicationDeadline": "2023-09-15"}
映画
映画を表すスキーマ。 title
、director
、release date
、genre
、duration
、cast members
などのプロパティを含みます。

スキーマ
{ "$id": "https://example.com/movie.schema.json", "$schema": "https://json-schema.dokyumento.jp/draft/2020-12/schema", "description": "A representation of a movie", "type": "object", "required": ["title", "director", "releaseDate"], "properties": { "title": { "type": "string" }, "director": { "type": "string" }, "releaseDate": { "type": "string", "format": "date" }, "genre": { "type": "string", "enum": ["Action", "Comedy", "Drama", "Science Fiction"] }, "duration": { "type": "string" }, "cast": { "type": "array", "items": { "type": "string" }, "additionalItems": false } }}
データ
{ "title": "サンプル映画", "director": "ジョン・ディレクター", "releaseDate": "2023-07-01", "genre": "アクション", "duration": "2時間15分", "cast": ["俳優A", "女優B", "俳優C"]}
ユーザープロファイル
ユーザープロファイルを表すスキーマ。 username
、email
、fullName
、age
、location
、interests
などのプロパティを含みます。

スキーマ
{ "$id": "https://example.com/user-profile.schema.json", "$schema": "https://json-schema.dokyumento.jp/draft/2020-12/schema", "description": "A representation of a user profile", "type": "object", "required": ["username", "email"], "properties": { "username": { "type": "string" }, "email": { "type": "string", "format": "email" }, "fullName": { "type": "string" }, "age": { "type": "integer", "minimum": 0 }, "location": { "type": "string" }, "interests": { "type": "array", "items": { "type": "string" } } }}
データ
{ "username": "user123", "email": "[email protected]", "fullName": "John Doe", "age": 30, "location": "Cityville", "interests": ["Travel", "Technology"]}