Modelica to JSON parser
1. General Description
Modelica-json is a translator that parses the Modelica language to JSON, HTML and docx. Two translation modes have been implemented : The first mode aims to parse Modelica packages and takes into input a directory of .mo files. The other mode aims to parse CDL files and takes a single .mo file compliant with the CDL language as input. For more information on the CDL Language, please refer to the OpenBuildingControl project website.
See the directory
test/FromModelica from Modelica-json for simple examples from Modelica and CDL to detailed and simplified JSON formats and HTML.
2. Installation and help
First, set the MODELICAPATH environment variable by adding the following line to your ~/.bashrc file:
The parser requires Java and node, which can be installed on Ubuntu using
sudo apt-get install nodejs npm default-jdk
To install dependencies of the parser, run
To compile the Java files, run
To run the test cases, run
To get more help, run
node app.js -h
To clean the current installation, run
First, make sure that both the
modelica-jsondirectory and the
Modelica Buildings Librarydirectory are in the folders that do not require administrator access. By saving the directories in driver other than
C:\would typical avoid the administrator access issue.
Then, create the
MODELICAPATHenvironment variable and set the value as the path of Modelica Buildings Library, like
Install Java SE Development Kit (64-bit version), Java Runtime Environment (64-bit version) and Node.js.
In batch file
JAVA_HOMEpath in line
Finally, to install dependencies and compile the Java files, run
To test the installation, from the
\modelica-json directory, run the parser on Command Prompt:
node app.js -f test\FromModelica\Modulation.mo
\modelica-json directory should have a new folder
html and in the folder, there is a file
FromModelica.Modulation.html and a sub-folder
3. How to use the parser
The parser can be run with the app.js file as follows:
node app.js -f <path of the file to parse>
–file / -f
The only required input is the path of the file or package to be parsed.
–output / -o
This parser takes a .mo file in input and has three possible outputs, that can be specified with the argument -o :
- raw-json : detailed transcription of a Modelica file in JSON
- json: simplified JSON format, easier to read an interpret
- html (default): transcription from json with links for documentation
- docx : transcription of the HTML documentation to an editable format
–mode / -m
We offer two different modes of translation that can be chosen with the argument -m :
- modelica : Parses a Modelica package (must be a directory)
- cdl (default) : Parses a CDL file.
–log / -l
Logging level. The choices are ‘error’, ‘warn’, ‘info’ (default), ‘verbose’, ‘debug’.
–directory / -d
Specify the output directory. The default option is the current directory.
4. JSON Schemas
The JSON representation of Modelica and CDL models must be compliant with the corresponding JSON Schema. This is applicable for the JSON output, not for the raw-json one.
JSON Schemas describe the data format and file structure to ensure the quality of the JSON files.
Two schemas are available (links to the raw files) :
- Schema-CDL.json validates the JSON files parsed from CDL
- Schema-modelica.json validates the JSON files parsed from Modelica models
Graphical viewers are available (please use right click + open in a new tab or refresh the page if necessary - this is not optimized for Firefox) :
When parsing a file using
app.js, the schema is chosen according to the mode.
To validate an existing JSON file against the schema, run
node validation.js -f <path to the json file>
The default schema is CDL. To chose the Modelica schema, run:
node validation.js -f <path to the json file> -m modelica
5. Useful Links
Modified 3-clause BSD, see LICENSE.md.
See copyright notice.