Posted on by Achim D. Brucker, licensed under CC BY-ND 4.0.

Working with JSON-Formatted Data in Isabelle

JSON (JavaScript Object Notation) is common format for exchanging data. Thus, sometimes it would be handy to be able to “import” JSON-formatted data into Isabelle/HOL, e.g., as part of a datatype package (implemented in Isabelle/ML) for using the data as part of a system verification (in Isabelle/HOL).

Using our AFP entry “Nano JSON” [1] this is now easy. It provides both import and export of JSON-formatted data into Isabelle - both on the level of Isabelle/ML and Isabelle/HOL. Thus, it allows users of Isabelle/HOL to work with JSON-formatted data in Isabelle without needing to implement import or export functionalities in ML. At the same time, user that want to implement their own datatype package can use the Isabelle/ML API provided by AFP entry “Nano JSON”.

For example, assuming a simple JSON encoded data like

{
    "menu": {
        "id": "file",
        "value": "File",
        "popup": {
            "menuitem": [
                {"value": "New", "onclick": "CreateNewDoc()"},
                {"value": "Open", "onclick": "OpenDoc()"},
                {"value": "Close", "onclick": "CloseDoc()"}
            ]
        }  
    }, 
    "flag":true, 
    "number":42
}

stored in a file example.json, you can now import this data into Isabelle

JSON_file "example.json" defining example

and use it in a formal context, such as

lemma ([STR ''onclick''], STRING STR ''CreateNewDoc()'')  set(nj_filter (STR ''onclick'') example_literal_literal)
  by(normalization)

Alternative ways of importing JSON

For short JSON-snippets, you can use an antiquotation:

lemma y == JSON {"name": true} 
  oops

Moreover, for you can also use a new Isar command that allows for inlining JSON into Isabelle theories:

JSON 
{
    "menu": {
        "id": "file",
        "value": "File",
        "popup": {
            "menuitem": [
                {"value": "New", "onclick": "CreateNewDoc()"},
                {"value": "Open", "onclick": "OpenDoc()"},
                {"value": "Close", "onclick": "CloseDoc()"}
            ]
        }  
    }, 
    "flag":true, 
    "number":42
}
 defining example04

Exporting JSON

Exporting JSON is easy, assuming that the data has already been converted the HOL-representation of JSON provided:

JSON_export example file example

References

[1]
A. D. Brucker, Nano JSON: Working with JSON formatted data in isabelle/HOL and isabelle/ML,” Archive of Formal Proofs, Jul. 2022,

Welcome to the blog of the Software Assurance & Security Research Team at the University of Exeter. We blog regularly news, tips & tricks, as well as fun facts about software assurance, reliability, security, testing, verification, hacking, and logic.

You can also follow us on Twitter: @logicalhacking.

Categories

Archive

Tags

academia ai android apidesign appsec bitcoin blockchain bpmn browser browserextensions browsersecurity bug certification chrome composition cordova dast devops devsecops dom dsbd efsm epsrc event extensions fixeffort floss formaldocument formalmethods funding hol-ocl hol-testgen humanfactor hybridapps iast industry internetofthings iot isabelle/hol isabelledof isadof latex logic maintance malicous mbst mobile mobile apps modelinference modeling monads monitoring msc ocl ontology opensource owasp patches pet phd phdlife phishing policy protocols publishing reliability research safelinks safety sap sast sdlc secdevops secureprogramming security securityengineering securitytesting semantics servicecomposition skills smartcontract smartthings softwareeinginering softwaresecurity softwaresupplychain solidity staff&positions statemachine studentproject tcb test&proof testing tips&tricks tools transport tuos uk uoe upgrade usability verification vulnerabilities vulnerableapplication webinar websecurity

Search


blog whole site