1{
2    "$schema": "http://json-schema.org/draft-04/schema#",
3    "description": "IPython Notebook v4.1 JSON schema.",
4    "type": "object",
5    "additionalProperties": false,
6    "required": ["metadata", "nbformat_minor", "nbformat", "cells"],
7    "properties": {
8        "metadata": {
9            "description": "Notebook root-level metadata.",
10            "type": "object",
11            "additionalProperties": true,
12            "properties": {
13                "kernelspec": {
14                    "description": "Kernel information.",
15                    "type": "object",
16                    "required": ["name", "display_name"],
17                    "properties": {
18                        "name": {
19                            "description": "Name of the kernel specification.",
20                            "type": "string"
21                        },
22                        "display_name": {
23                            "description": "Name to display in UI.",
24                            "type": "string"
25                        }
26                    }
27                },
28                "language_info": {
29                  "description": "Kernel information.",
30                  "type": "object",
31                  "required": ["name"],
32                  "properties": {
33                    "name": {
34                        "description": "The programming language which this kernel runs.",
35                        "type": "string"
36                    },
37                    "codemirror_mode": {
38                        "description": "The codemirror mode to use for code in this language.",
39                        "oneOf": [
40                          {"type": "string"},
41                          {"type": "object"}
42                        ]
43                    },
44                    "file_extension": {
45                        "description": "The file extension for files in this language.",
46                        "type": "string"
47                    },
48                    "mimetype": {
49                        "description": "The mimetype corresponding to files in this language.",
50                        "type": "string"
51                    },
52                    "pygments_lexer": {
53                        "description": "The pygments lexer to use for code in this language.",
54                        "type": "string"
55                    }
56                  }
57                },
58                "orig_nbformat": {
59                    "description": "Original notebook format (major number) before converting the notebook between versions. This should never be written to a file.",
60                    "type": "integer",
61                    "minimum": 1
62                }
63            }
64        },
65        "nbformat_minor": {
66            "description": "Notebook format (minor number). Incremented for backward compatible changes to the notebook format.",
67            "type": "integer",
68            "minimum": 1
69        },
70        "nbformat": {
71            "description": "Notebook format (major number). Incremented between backwards incompatible changes to the notebook format.",
72            "type": "integer",
73            "minimum": 4,
74            "maximum": 4
75        },
76        "cells": {
77            "description": "Array of cells of the current notebook.",
78            "type": "array",
79            "items": {"$ref": "#/definitions/cell"}
80        }
81    },
82
83    "definitions": {
84        "cell": {
85            "type": "object",
86            "oneOf": [
87                {"$ref": "#/definitions/raw_cell"},
88                {"$ref": "#/definitions/markdown_cell"},
89                {"$ref": "#/definitions/code_cell"}
90            ]
91        },
92
93        "raw_cell": {
94            "description": "Notebook raw nbconvert cell.",
95            "type": "object",
96            "additionalProperties": false,
97            "required": ["cell_type", "metadata", "source"],
98            "properties": {
99                "cell_type": {
100                    "description": "String identifying the type of cell.",
101                    "enum": ["raw"]
102                },
103                "metadata": {
104                    "description": "Cell-level metadata.",
105                    "type": "object",
106                    "additionalProperties": true,
107                    "properties": {
108                        "format": {
109                            "description": "Raw cell metadata format for nbconvert.",
110                            "type": "string"
111                        },
112                        "name": {"$ref": "#/definitions/misc/metadata_name"},
113                        "tags": {"$ref": "#/definitions/misc/metadata_tags"}
114                    }
115                },
116                "attachments": {"$ref": "#/definitions/misc/attachments"},
117                "source": {"$ref": "#/definitions/misc/source"}
118            }
119        },
120
121        "markdown_cell": {
122            "description": "Notebook markdown cell.",
123            "type": "object",
124            "additionalProperties": false,
125            "required": ["cell_type", "metadata", "source"],
126            "properties": {
127                "cell_type": {
128                    "description": "String identifying the type of cell.",
129                    "enum": ["markdown"]
130                },
131                "metadata": {
132                    "description": "Cell-level metadata.",
133                    "type": "object",
134                    "properties": {
135                        "name": {"$ref": "#/definitions/misc/metadata_name"},
136                        "tags": {"$ref": "#/definitions/misc/metadata_tags"}
137                    },
138                    "additionalProperties": true
139                },
140                "attachments": {"$ref": "#/definitions/misc/attachments"},
141                "source": {"$ref": "#/definitions/misc/source"}
142            }
143        },
144
145        "code_cell": {
146            "description": "Notebook code cell.",
147            "type": "object",
148            "additionalProperties": false,
149            "required": ["cell_type", "metadata", "source", "outputs", "execution_count"],
150            "properties": {
151                "cell_type": {
152                    "description": "String identifying the type of cell.",
153                    "enum": ["code"]
154                },
155                "metadata": {
156                    "description": "Cell-level metadata.",
157                    "type": "object",
158                    "additionalProperties": true,
159                    "properties": {
160                        "collapsed": {
161                            "description": "Whether the cell is collapsed/expanded.",
162                            "type": "boolean"
163                        },
164                        "scrolled": {
165                            "description": "Whether the cell's output is scrolled, unscrolled, or autoscrolled.",
166                            "enum": [true, false, "auto"]
167                        },
168                        "name": {"$ref": "#/definitions/misc/metadata_name"},
169                        "tags": {"$ref": "#/definitions/misc/metadata_tags"}
170                    }
171                },
172                "source": {"$ref": "#/definitions/misc/source"},
173                "outputs": {
174                    "description": "Execution, display, or stream outputs.",
175                    "type": "array",
176                    "items": {"$ref": "#/definitions/output"}
177                },
178                "execution_count": {
179                    "description": "The code cell's prompt number. Will be null if the cell has not been run.",
180                    "type": ["integer", "null"],
181                    "minimum": 0
182                }
183            }
184        },
185
186        "unrecognized_cell": {
187            "description": "Unrecognized cell from a future minor-revision to the notebook format.",
188            "type": "object",
189            "additionalProperties": true,
190            "required": ["cell_type", "metadata"],
191            "properties": {
192                "cell_type": {
193                    "description": "String identifying the type of cell.",
194                    "not" : {
195                      "enum": ["markdown", "code", "raw"]
196                    }
197                },
198                "metadata": {
199                    "description": "Cell-level metadata.",
200                    "type": "object",
201                    "properties": {
202                        "name": {"$ref": "#/definitions/misc/metadata_name"},
203                        "tags": {"$ref": "#/definitions/misc/metadata_tags"}
204                    },
205                    "additionalProperties": true
206                }
207            }
208        },
209
210        "output": {
211            "type": "object",
212            "oneOf": [
213                {"$ref": "#/definitions/execute_result"},
214                {"$ref": "#/definitions/display_data"},
215                {"$ref": "#/definitions/stream"},
216                {"$ref": "#/definitions/error"}
217            ]
218        },
219
220        "execute_result": {
221            "description": "Result of executing a code cell.",
222            "type": "object",
223            "additionalProperties": false,
224            "required": ["output_type", "data", "metadata", "execution_count"],
225            "properties": {
226                "output_type": {
227                    "description": "Type of cell output.",
228                    "enum": ["execute_result"]
229                },
230                "execution_count": {
231                    "description": "A result's prompt number.",
232                    "type": ["integer", "null"],
233                    "minimum": 0
234                },
235                "data": {"$ref": "#/definitions/misc/mimebundle"},
236                "metadata": {"$ref": "#/definitions/misc/output_metadata"}
237            }
238        },
239
240        "display_data": {
241            "description": "Data displayed as a result of code cell execution.",
242            "type": "object",
243            "additionalProperties": false,
244            "required": ["output_type", "data", "metadata"],
245            "properties": {
246                "output_type": {
247                    "description": "Type of cell output.",
248                    "enum": ["display_data"]
249                },
250                "data": {"$ref": "#/definitions/misc/mimebundle"},
251                "metadata": {"$ref": "#/definitions/misc/output_metadata"}
252            }
253        },
254
255        "stream": {
256            "description": "Stream output from a code cell.",
257            "type": "object",
258            "additionalProperties": false,
259            "required": ["output_type", "name", "text"],
260            "properties": {
261                "output_type": {
262                    "description": "Type of cell output.",
263                    "enum": ["stream"]
264                },
265                "name": {
266                    "description": "The name of the stream (stdout, stderr).",
267                    "type": "string"
268                },
269                "text": {
270                    "description": "The stream's text output, represented as an array of strings.",
271                    "$ref": "#/definitions/misc/multiline_string"
272                }
273            }
274        },
275
276        "error": {
277            "description": "Output of an error that occurred during code cell execution.",
278            "type": "object",
279            "additionalProperties": false,
280            "required": ["output_type", "ename", "evalue", "traceback"],
281            "properties": {
282                "output_type": {
283                    "description": "Type of cell output.",
284                    "enum": ["error"]
285                },
286                "ename": {
287                    "description": "The name of the error.",
288                    "type": "string"
289                },
290                "evalue": {
291                    "description": "The value, or message, of the error.",
292                    "type": "string"
293                },
294                "traceback": {
295                    "description": "The error's traceback, represented as an array of strings.",
296                    "type": "array",
297                    "items": {"type": "string"}
298                }
299            }
300        },
301
302        "unrecognized_output": {
303            "description": "Unrecognized output from a future minor-revision to the notebook format.",
304            "type": "object",
305            "additionalProperties": true,
306            "required": ["output_type"],
307            "properties": {
308                "output_type": {
309                    "description": "Type of cell output.",
310                    "not": {
311                        "enum": ["execute_result", "display_data", "stream", "error"]
312                    }
313                }
314            }
315        },
316
317        "misc": {
318            "metadata_name": {
319                "description": "The cell's name. If present, must be a non-empty string.",
320                "type": "string",
321                "pattern": "^.+$"
322            },
323            "metadata_tags": {
324                "description": "The cell's tags. Tags must be unique, and must not contain commas.",
325                "type": "array",
326                "uniqueItems": true,
327                "items": {
328                    "type": "string",
329                    "pattern": "^[^,]+$"
330                }
331            },
332            "attachments": {
333                "description": "Media attachments (e.g. inline images), stored as mimebundle keyed by filename.",
334                "type": "object",
335                "patternProperties": {
336                    ".*": {
337                        "description": "The attachment's data stored as a mimebundle.",
338                        "$ref": "#/definitions/misc/mimebundle"
339                    }
340                }
341            },
342            "source": {
343                "description": "Contents of the cell, represented as an array of lines.",
344                "$ref": "#/definitions/misc/multiline_string"
345            },
346            "execution_count": {
347                "description": "The code cell's prompt number. Will be null if the cell has not been run.",
348                "type": ["integer", "null"],
349                "minimum": 0
350            },
351            "mimebundle": {
352                "description": "A mime-type keyed dictionary of data",
353                "type": "object",
354                "additionalProperties": {
355                  "description": "mimetype output (e.g. text/plain), represented as either an array of strings or a string.",
356                  "$ref": "#/definitions/misc/multiline_string"
357                },
358                "patternProperties": {
359                    "^application/(.*\\+)?json$": {
360                        "description": "Mimetypes with JSON output, can be any type"
361                    }
362                }
363            },
364            "output_metadata": {
365                "description": "Cell output metadata.",
366                "type": "object",
367                "additionalProperties": true
368            },
369            "multiline_string": {
370                "oneOf" : [
371                    {"type": "string"},
372                    {
373                        "type": "array",
374                        "items": {"type": "string"}
375                    }
376                ]
377            }
378        }
379    }
380}
381