Theory Nano_JSON
section‹An Import/Export of JSON-like Formats for Isabelle/HOL›
theory
"Nano_JSON"
imports
Main
keywords
"JSON_file" :: thy_load
and "JSON" :: thy_decl
and "JSON_export" :: thy_decl
and "defining"::quasi_command
begin
text‹
This theory implements an import/export format for Isabelle/HOL that is inspired by
JSON (JavaScript Object Notation). While the format defined in this theory is inspired
by the JSON standard (@{url "https://www.json.org"}), it is not fully compliant. Most
notably,
▪ only basic support for Unicode characters. In particular, JSON strings are mapped to a
polymorphic type usually is either instantiated with the @{type "string"} or
@{type "String.literal"}. Hence, the strings that can be represented in JSON are limited
by the characters that Isabelle/HOL can handle (support on the Isabelle/ML level is
less constrained).
▪ numbers are mapped to a polymorphic type, which can, e.g., be instantiated with
▪ @{term "real"}. Note that this is not a faithful representation of IEEE754 floating
point numbers that are assumed in the JSON standard. Moreover, this required that
parent theories include Complex\_Main.
▪ @{type "int"}. This is recommended configuration, if the JSON files only contain integers
as numerical data.
▪ @{type "string"}. If not numerical operations need to be done, numberical values can also
be encoded as HOL strings (or @{type "String.literal"}).
While the provided JSON import and export mechanism is not fully compliant to the JSON standard
(hence, its name ``Nano JSON''), it should work with most real-world JSON files. Actually, it
has already served well in various projects, allowing us to simply exchange data between Isabelle/HOL
and external tools.
›
subsection‹Defining a JSON-like Data Structure›
text‹
We start by modelling a HOL data type for representing the abstract syntax of JSON, which
consists out of objects, lists (called arrays), numbers, strings, and Boolean values.
›
subsubsection‹A HOL Data Type for JSON›