Skip to content

Commit eb23147

Browse files
Charlie OwenPhil Sturgeon
authored andcommitted
Updating the examples markdown.
1 parent b27156f commit eb23147

File tree

3 files changed

+150
-31
lines changed

3 files changed

+150
-31
lines changed

_includes/.DS_Store

6 KB
Binary file not shown.

_includes/person.json

Lines changed: 0 additions & 18 deletions
This file was deleted.

examples.md

Lines changed: 150 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,163 @@ layout: page
33
title: Examples
44
---
55

6-
Here is a basic example of a JSON Schema:
6+
## Basic
7+
8+
This example provides a typical minimum you are going to see in JSON Schema. It contains:
9+
10+
* [`$id` keyword](http://json-schema.org/latest/json-schema-core.html#rfc.section.8.2)
11+
* [`$schema` keyword](http://json-schema.org/latest/json-schema-core.html#rfc.section.7)
12+
* [`title` link target attribute](http://json-schema.org/latest/json-schema-hypermedia.html#rfc.section.6.5.1)
13+
* [`type` instance data model](http://json-schema.org/latest/json-schema-core.html#rfc.section.4.2.1)
14+
* [`properties` object validation keyword](http://json-schema.org/latest/json-schema-validation.html#rfc.section.6.5.4)
15+
* Three keys: `firstName`, `lastName` and `age` each with their own:
16+
* [`description` annotation](http://json-schema.org/latest/json-schema-validation.html#rfc.section.10.1)
17+
* `type` instance data model (see above).
18+
* [`minimum` validation keyword](http://json-schema.org/latest/json-schema-validation.html#rfc.section.6.2.4) on the `age` key.
19+
20+
```json
21+
{
22+
"$id": "https://example.com/person.schema.json",
23+
"$schema": "http://json-schema.org/draft-07/schema#",
24+
"title": "Person",
25+
"type": "object",
26+
"properties": {
27+
"firstName": {
28+
"type": "string",
29+
"description": "The person's first name."
30+
},
31+
"lastName": {
32+
"type": "string",
33+
"description": "The person's last name."
34+
},
35+
"age": {
36+
"description": "Age in years which must be equal to or greater than zero.",
37+
"type": "integer",
38+
"minimum": 0
39+
}
40+
}
41+
}
42+
```
43+
44+
**Data**
45+
46+
```json
47+
{
48+
"firstName": "John",
49+
"lastName": "Doe",
50+
"age": 21
51+
}
52+
```
53+
54+
## Describing geographical coordinates.
55+
56+
This example introduces:
57+
58+
* [`required` object validation keyword](http://json-schema.org/latest/json-schema-validation.html#rfc.section.6.5.3)
59+
* [`minimum` validation keyword](http://json-schema.org/latest/json-schema-validation.html#rfc.section.6.2.4)
60+
* [`maximum` validation keyword](http://json-schema.org/latest/json-schema-validation.html#rfc.section.6.2.2)
61+
762

863
```json
9-
{% include person.json%}
64+
{
65+
"id": "https://example.com/geographical-___location.schema.json",
66+
"$schema": "http://json-schema.org/draft-07/schema#",
67+
"title": "Longitude and Latitude Values",
68+
"description": "A geographical coordinate.",
69+
"required": [ "latitude", "longitude" ],
70+
"type": "object",
71+
"properties": {
72+
"latitude": {
73+
"type": "number",
74+
"minimum": -90,
75+
"maximum": 90
76+
},
77+
"longitude": {
78+
"type": "number",
79+
"minimum": -180,
80+
"maximum": 180
81+
}
82+
}
83+
}
1084
```
1185

12-
Example schemas
13-
---------------
86+
**Data**
1487

15-
These sample schemas describe simple data structures which can be expressed as JSON. The "canonical url" links omit the ".json" extension, which is the correct
16-
way to reference the schema in a ``$ref``, but is not friendly to web browsers.
17-
The larger links use ".json" for browser compatibility.
88+
```json
89+
{
90+
"latitude": 48.858093,
91+
"longitude": 2.294694
92+
}
93+
```
94+
95+
## Arrays of things
96+
97+
Arrays are fundamental structures in JSON -- here we demonstrate a couple of ways they can be described:
98+
99+
* An array of string values.
100+
* An array of objects.
101+
102+
We also introduce the following with this example:
103+
104+
* [`definitions` keyword](http://json-schema.org/latest/json-schema-validation.html#rfc.section.9)
105+
* [`$ref` keyword](http://json-schema.org/latest/json-schema-core.html#rfc.section.8.3)
18106

19-
|------------------------------------------------------------------------------|-----------------------------------------------------------------|
20-
| [Geographic Coordinate](example/geo.json) <br> [<small>(canonical url)</small>](geo) | a ___location as longitude and latitude |
21-
| [Card](example/card.json) <br> [<small>(canonical url)</small>](card) | a microformat-style representation of a person, company, organization, or place |
22-
| [Calendar](example/calendar.json) <br> [<small>(canonical url)</small>](calendar) | a microformat-style representation of an event |
23-
| [Address](example/address.json) <br> [<small>(canonical url)</small>](address) | a microformat-style representation of a street address |
107+
```json
108+
{
109+
"id": "https://example.com/arrays.schema.json",
110+
"$schema": "http://json-schema.org/draft-07/schema#",
111+
"description": "A representation of a person, company, organization, or place",
112+
"type": "object",
113+
"properties": {
114+
"fruits": {
115+
"type": "array",
116+
"items": {
117+
"type": "string"
118+
}
119+
},
120+
"vegetables": {
121+
"type": "array",
122+
"items": { "$ref": "#/definitions/veggie" }
123+
}
124+
},
125+
"definitions": {
126+
"veggie": {
127+
"type": "object",
128+
"required": [ "veggieName", "veggieLike" ],
129+
"properties": {
130+
"veggieName": {
131+
"type": "string",
132+
"description": "The name of the vegetable."
133+
},
134+
"veggieLike": {
135+
"type": "boolean",
136+
"description": "Do I like this vegetable?"
137+
}
138+
}
139+
}
140+
}
141+
}
142+
```
143+
144+
**Data**
145+
146+
```json
147+
{
148+
"fruits": [ "apple", "orange", "pear" ],
149+
"vegetables": [
150+
{
151+
"veggieName": "potato",
152+
"veggieLike": true
153+
},
154+
{
155+
"veggieName": "broccoli",
156+
"veggieLike": false
157+
}
158+
]
159+
}
160+
```
24161

25-
Walkthroughs
162+
## Walkthroughs
26163
------------
27164

28165
The two examples below are step-by-step guides into building a schema:

0 commit comments

Comments
 (0)