At the highest level, a Jupyter notebook is a dictionary with a few keys:

metadata (dict)

nbformat (int)

nbformat_minor (int)

cells (list)

{"metadata":{"kernel_info":{# if kernel_info is defined, its name field is required."name":"the name of the kernel"},"language_info":{# if language_info is defined, its name field is required."name":"the programming language of the kernel","version":"the version of the language","codemirror_mode":"The name of the codemirror mode to use [optional]"}},"nbformat":4,"nbformat_minor":0,"cells":[# list of cell dictionaries, see below],}

Some fields, such as code input and text output, are characteristically multi-line strings.
When these fields are written to disk, they may be written as a list of strings,
which should be joined with '' when reading back into memory.
In programmatic APIs for working with notebooks (Python, Javascript),
these are always re-joined into the original multi-line string.
If you intend to work with notebook files directly,
you must allow multi-line string fields to be either a string or list of strings.

Code cells are the primary content of Jupyter notebooks.
They contain source code in the language of the document’s associated kernel,
and a list of outputs associated with executing that code.
They also have an execution_count, which must be an integer or null.

{"cell_type":"code","execution_count":1,# integer or null"metadata":{"collapsed":True,# whether the output of the cell is collapsed"autoscroll":False,# any of true, false or "auto"},"source":"[some multi-line code]","outputs":[{# list of output dicts (described below)"output_type":"stream",...}],}

Rich display outputs, as created by display_data messages,
contain data keyed by mime-type. This is often called a mime-bundle,
and shows up in various locations in the notebook format and message spec.
The metadata of these messages may be keyed by mime-type as well.

mime-types are used for keys, instead of a combination of short names (text)
and mime-types, and are stored in a data key, rather than the top-level.
i.e. output.data['image/png'] instead of output.png.

Results of executing a cell (as created by displayhook in Python)
are stored in execute_result outputs.
execute_result outputs are identical to display_data,
adding only a execution_count field, which must be an integer.

{'output_type':'error','ename':str,# Exception name, as a string'evalue':str,# Exception value, as a string# The traceback will contain a list of frames,# represented each as a string.'traceback':list,}

A raw cell is defined as content that should be included unmodified in nbconvert output.
For example, this cell could include raw LaTeX for nbconvert to pdf via latex,
or restructured text for use in Sphinx documentation.

The notebook authoring environment does not render raw cells.

The only logic in a raw cell is the format metadata field.
If defined, it specifies which nbconvert output format is the intended target
for the raw cell. When outputting to any other format,
the raw cell’s contents will be excluded.
In the default case when this value is undefined,
a raw cell’s contents will be included in any nbconvert output,
regardless of format.

{"cell_type":"raw","metadata":{# the mime-type of the target nbconvert format.# nbconvert to formats other than this will exclude this cell."format":"mime/type"},"source":"[some nbformat output text]"}

Markdown and raw cells can have a number of attachments, typically inline
images that can be referenced in the markdown content of a cell. The attachments
dictionary of a cell contains a set of mime-bundles (see display_data)
keyed by filename that represents the files attached to the cell.

Note

The attachments dictionary is an optional field and can be undefined or empty if the cell does not have any attachments.

The notebook format is an evolving format. When backward-compatible changes are made,
the notebook format minor version is incremented. When backward-incompatible changes are made,
the major version is incremented.

As of nbformat 4.x, backward-compatible changes include:

new fields in any dictionary (notebook, cell, output, metadata, etc.)

new cell types

new output types

New cell or output types will not be rendered in versions that do not recognize them,
but they will be preserved.

Metadata is a place that you can put arbitrary JSONable information about
your notebook, cell, or output. Because it is a shared namespace,
any custom metadata should use a sufficiently unique namespace,
such as metadata.kaylees_md.foo = “bar”.