Skip to content
This repository was archived by the owner on Nov 2, 2023. It is now read-only.

Commit 3123555

Browse files
committed
Merge pull request #67 from geraintluff/gh-pages-merge
Website overhaul
2 parents eb4805e + 7890044 commit 3123555

27 files changed

+6570
-997
lines changed

content/documentation.html

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<h2>Specification</h2>
2+
<div class="block">
3+
<p>The latest IETF published draft is <a href="http://tools.ietf.org/html/draft-zyp-json-schema-03">v3</a>. However, a newer version of the specification is being prepared for submission in early 2013.
4+
5+
<p>The latest specifications are available here:
6+
7+
<p>
8+
<table class="key-value">
9+
<tr>
10+
<td class="key"><a href="latest/json-schema-core.html">JSON Schema Core</a></td>
11+
<td class="value">defines the basic foundation of JSON Schema</td>
12+
</tr>
13+
<tr>
14+
<td class="key"><a href="latest/json-schema-validation.html">JSON Schema Validation</a></td>
15+
<td class="value">defines the validation keywords of JSON Schema</td>
16+
</tr>
17+
<tr>
18+
<td class="key"><a href="latest/json-schema-core.html">JSON Hyper-Schema</a></td>
19+
<td class="value">defines the hyper-media keywords of JSON Schema</td>
20+
</tr>
21+
</table>
22+
</div>
23+
24+
<h2>Meta-schemas</h2>
25+
<div class="block">
26+
<p>The meta-schemas are the schemas which define the JSON Schema and Hyper-Schema formats.
27+
28+
<p>
29+
<table class="key-value">
30+
<tr>
31+
<td class="key"><a href="http://json-schema.org/schema">Core/Validation Meta-Schema</a></td>
32+
<td class="value">Used for schemas written for pure validation.</td>
33+
</tr>
34+
<tr>
35+
<td class="key"><a href="http://json-schema.org/hyper-schema">Hyper Meta-Schema</a></td>
36+
<td class="value">Used for schemas written for validation and hyper-linking.</td>
37+
</tr>
38+
</table>
39+
</div>
40+
41+
<h2>Standard schemas</h2>
42+
<div class="block">
43+
<p>These sample schemas describe simple data structures which can be expressed as JSON:
44+
45+
<p>
46+
<table class="key-value">
47+
<tr>
48+
<td class="key"><a href="http://json-schema.org/geo">Geographic Coordinate</a></td>
49+
<td class="value">a location as longitude and latitude</td>
50+
</tr>
51+
<tr>
52+
<td class="key"><a href="http://json-schema.org/card">Card</a></td>
53+
<td class="value">a microformat-style representation of a person, company, organization, or place</td>
54+
</tr>
55+
<tr>
56+
<td class="key"><a href="http://json-schema.org/calendar">Calendar</a></td>
57+
<td class="value">a microformat-style representation of an event</td>
58+
</tr>
59+
<tr>
60+
<td class="key"><a href="http://json-schema.org/address">Address</a></td>
61+
<td class="value">a microformat-style representation of a street address</td>
62+
</tr>
63+
</table>
64+
</div>

example.html renamed to content/example1.html

Lines changed: 58 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,9 @@
1-
<!DOCTYPE html>
2-
<html>
3-
<head>
4-
<title></title>
5-
<link href="lib/bootstrap-min.css" rel="stylesheet">
6-
<link rel="stylesheet" href="lib/json-highlight.css"></link>
7-
</head>
8-
<body>
9-
<div class="container">
10-
<div class="row">
11-
<div class="span8">
12-
<div class="page-header">
13-
<h1>JSON Schema Examples</h1>
14-
</div>
15-
</div>
16-
</div>
17-
<div class="row">
18-
<div class="span8">
19-
<h2>JSON Schema by example</h2>
20-
21-
<p>Let's pretend we're interacting with a JSON based product catalog. This catalog has a product which has an <em>id</em>, a <em>name</em>, a <em>price</em>, and an optional set of <em>tags</em>.
22-
</p>
1+
<h2>Example data</h2>
2+
<div class="block">
3+
<p>Let's pretend we're interacting with a JSON based product catalog. This catalog has a product which has an <em>id</em>, a <em>name</em>, a <em>price</em>, and an optional set of <em>tags</em>.</p>
234

24-
<h3>Example JSON data for a product API</h3>
25-
<p>An example product in this API is:</p>
5+
<h3>Example JSON data for a product API</h3>
6+
<p>An example product in this API is:</p>
267

278
<pre class="json">
289
{
@@ -33,18 +14,21 @@ <h3>Example JSON data for a product API</h3>
3314
}
3415
</pre>
3516

36-
<p>While generally straightforward, that example leaves some open questions. For example, one may ask:</p>
17+
<p>While generally straightforward, that example leaves some open questions. For example, one may ask:</p>
18+
19+
<ul>
20+
<li>What is id?</li>
21+
<li>Is name required?</li>
22+
<li>Can price be 0?</li>
23+
<li>Are all tags strings?</li>
24+
</ul>
3725

38-
<ul>
39-
<li>What is id?</li>
40-
<li>Is name required?</li>
41-
<li>Can price be 0?</li>
42-
<li>Are all tags strings?</li>
43-
</ul>
26+
<p>When you're talking about a data format, you want to have metadata about what fields mean, and what valid inputs for those fields are. JSON schema is a specification for standardizing how to answer those questions for JSON data.</p>
27+
</div>
4428

45-
<p>When you're talking about a data format, you want to have metadata about what fields mean, and what valid inputs for those fields are. JSON schema is a specification for standardizing how to answer those questions for JSON data.</p>
46-
<h3>Example schema for the product API</h3>
47-
<p>To start a schema definition, let's begin with a basic JSON schema:</p>
29+
<h2>Starting the schema</h2>
30+
<div class="block">
31+
<p>To start a schema definition, let's begin with a basic JSON schema:</p>
4832

4933
<pre class="json-schema">
5034
{
@@ -55,24 +39,27 @@ <h3>Example schema for the product API</h3>
5539
}
5640
</pre>
5741

58-
<p>The above schema has four properties called <em>keywords</em>.
42+
<p>The above schema has four properties called <em>keywords</em>.
5943

60-
The <em>title</em> and <em>description</em> keywords are descriptive only, in that they do not add
61-
constraints to the data being validated. The intent of the schema is stated with these two keywords
62-
(that is, this schema describes a product).</p>
44+
The <em>title</em> and <em>description</em> keywords are descriptive only, in that they do not add
45+
constraints to the data being validated. The intent of the schema is stated with these two keywords
46+
(that is, this schema describes a product).</p>
6347

64-
<p>The <em>type</em> keyword defines the first constraint on our JSON data: it has to be a JSON
65-
Object.</p>
48+
<p>The <em>type</em> keyword defines the first constraint on our JSON data: it has to be a JSON
49+
Object.</p>
6650

67-
<p>Finally, the <em>$schema</em> keyword states that this schema is written according to the draft
68-
v4 specification.</p>
51+
<p>Finally, the <em>$schema</em> keyword states that this schema is written according to the draft
52+
v4 specification.</p>
53+
</div>
6954

70-
<p>Next let's answer our previous questions about this API, starting with id.</p>
55+
<h2>Defining the properties</h2>
56+
<div class="block">
57+
<p>Next let's answer our previous questions about this API, starting with id.</p>
7158

72-
<h4>What is id?</h4>
73-
<p><em>id</em> is a numeric value that uniquely identifies a product. Since this is the canonical identifier for a product, it doesn't make sense to have a product without one, so it is required.</p>
59+
<h3>What is id?</h3>
60+
<p><em>id</em> is a numeric value that uniquely identifies a product. Since this is the canonical identifier for a product, it doesn't make sense to have a product without one, so it is required.</p>
7461

75-
<p>In JSON Schema terms, we can update our schema to:</p>
62+
<p>In JSON Schema terms, we can update our schema to:</p>
7663
<pre class="json-schema">
7764
{
7865
"$schema": "http://json-schema.org/draft-04/schema#",
@@ -89,9 +76,9 @@ <h4>What is id?</h4>
8976
}
9077
</pre>
9178

92-
<h4>Is name required?</h4>
93-
<p><em>name</em> is a string value that describes a product. Since there isn't
94-
much to a product without a name, it also is required. Adding this gives us the schema:</p>
79+
<h3>Is name required?</h3>
80+
<p><em>name</em> is a string value that describes a product. Since there isn't
81+
much to a product without a name, it also is required. Adding this gives us the schema:</p>
9582

9683
<pre class="json-schema">
9784
{
@@ -113,8 +100,8 @@ <h4>Is name required?</h4>
113100
}
114101
</pre>
115102

116-
<h4>Can price be 0?</h4>
117-
<p>According to Acme's docs, there are no free products. In JSON schema a number can have a minimum. By default this minimum is inclusive, so we need to specify <em>exclusiveMinimum</em>. Therefore we can update our schema with <em>price</em>:</p>
103+
<h3>Can price be 0?</h3>
104+
<p>According to Acme's docs, there are no free products. In JSON schema a number can have a minimum. By default this minimum is inclusive, so we need to specify <em>exclusiveMinimum</em>. Therefore we can update our schema with <em>price</em>:</p>
118105

119106
<pre class="json-schema">
120107
{
@@ -141,21 +128,21 @@ <h4>Can price be 0?</h4>
141128
}
142129
</pre>
143130

144-
<h4>Are all tags strings?</h4>
145-
<p>Finally, we come to the <em>tags</em> property. Unlike the previous
146-
properties, tags have many values, and is represented as a JSON array. According
147-
to Acme's docs, all tags must be strings, but you aren't required to specify
148-
tags. We simply leave <em>tags</em> out of the list of required properties.</p>
131+
<h3>Are all tags strings?</h3>
132+
<p>Finally, we come to the <em>tags</em> property. Unlike the previous
133+
properties, tags have many values, and is represented as a JSON array. According
134+
to Acme's docs, all tags must be strings, but you aren't required to specify
135+
tags. We simply leave <em>tags</em> out of the list of required properties.</p>
149136

150-
<p>However, Acme's docs add two constraints:</p>
137+
<p>However, Acme's docs add two constraints:</p>
151138

152-
<ul>
153-
<li>there must be at least one tag,</li>
154-
<li>all tags must be unique.</li>
155-
</ul>
139+
<ul>
140+
<li>there must be at least one tag,</li>
141+
<li>all tags must be unique.</li>
142+
</ul>
156143

157-
<p>The first constraint can be added with <em>minItems</em>, and the second one by
158-
specifying <em>uniqueItems</em> as being true:</p>
144+
<p>The first constraint can be added with <em>minItems</em>, and the second one by
145+
specifying <em>uniqueItems</em> as being true:</p>
159146

160147
<pre class="json-schema">
161148
{
@@ -189,15 +176,15 @@ <h4>Are all tags strings?</h4>
189176
"required": ["id", "name", "price"]
190177
}
191178
</pre>
179+
</div>
192180

193-
<h3>Example summary</h3>
194-
<p>The above example is by no means definitive of all the types of data JSON schema can define. For more definitive information see the <a href="#definitions">full standard draft</a>.</p>
195-
196-
<p>As a final example, here's a spec for an array of products, with the products having 2 new properties. The first is a <em>dimensions</em> property for the size of the product, and the second is a <em>warehouseLocation</em> field for where the warehouse that stores them is geographically located.</p>
197-
198-
<p>And also, since JSON Schema defines a reference schema for a geographic location, instead of coming up with our own, we'll reference the <a href="http://json-schema.org/geo">canonical one</a>.</p>
181+
<h2>Summary</h2>
182+
<div class="block">
183+
<p>The above example is by no means definitive of all the types of data JSON schema can define. For more definitive information see the <a href="#definitions">full standard draft</a>.</p>
184+
<p>As a final example, here's a spec for an array of products, with the products having 2 new properties. The first is a <em>dimensions</em> property for the size of the product, and the second is a <em>warehouseLocation</em> field for where the warehouse that stores them is geographically located.</p>
185+
<p>And also, since JSON Schema defines a reference schema for a geographic location, instead of coming up with our own, we'll reference the <a href="http://json-schema.org/geo">canonical one</a>.</p>
199186

200-
<h4>Set of products:</h4>
187+
<h3>Set of products:</h3>
201188
<pre class="json">
202189
[
203190
{
@@ -232,8 +219,7 @@ <h4>Set of products:</h4>
232219
]
233220
</pre>
234221

235-
<h4>Set of products schema:</h4>
236-
222+
<h3>Set of products schema:</h3>
237223
<pre class="json-schema">
238224
{
239225
"$schema": "http://json-schema.org/draft-04/schema#",
@@ -281,11 +267,5 @@ <h4>Set of products schema:</h4>
281267
}
282268
}
283269
</pre>
284-
285-
</div>
286-
</div>
287270
</div>
288271

289-
<script src="lib/json-highlight.js"></script>
290-
</body>
291-
</html>

0 commit comments

Comments
 (0)