JSON-Fortran 5.3.0

JSON-Fortran 5.3.0 is out. This release includes a few minor bug fixes and a couple of new features. For one thing, it is now possible to easily build or modify a JSON structure without using pointer variables. Here’s an example:

program test

use json_module, rk=>json_rk

implicit none

type(json_file) :: f

call f%initialize()

call f%add('name',         'test')
call f%add('inputs.t',     0.0_rk)
call f%add('inputs.x',     [1.0_rk,2.0_rk,3.0_rk])
call f%add('outputs.t',    10.0_rk)
call f%add('outputs.x(1)', 11.0_rk)
call f%add('outputs.x(2)', 22.0_rk)
call f%add('outputs.x(3)', 33.0_rk)

call f%print_file()

call f%destroy()

end program test

As shown, the structure can be built by specifying the variable paths. This way, objects, vectors, vector elements, etc. can all be added. The result of this example is:

  "name": "test",
  "inputs": {
    "t": 0.0E+0,
    "x": [
  "outputs": {
    "t": 0.1E+2,
    "x": [

So now, in addition to the previous methods of building a JSON structure (reading it from a file, reading it from a string, or building it yourself using pointer variables), there is now another way. Each method has its uses for different applications. Building it from the path strings can be very convenient and also opens up the possibility of easy conversion between a Fortran namelist and a JSON file. I’ll show an example of this in a future post. In a previous post, I showed how to do the reverse (JSON to namelist).

JSON-Fortran is my most popular GitHub project (70 stars as of today). It usually makes it to GitHub’s monthly “trending” Fortran projects page. I’m always interested to hear about what people are using it for. I added a page on the wiki to list some of the projects that use it, so if you’re using it, feel free to add your project to the list.

Tagged with: ,
3 comments on “JSON-Fortran 5.3.0
  1. Stefano says:

    Hi Jacob,

    I added OpenPDE project to your list: although json-fortran is currently used in few cases, its usage will increase in the future.

    I use json-fortran also into another project, but it is not FOSS (for now).


  2. Colin Watters says:

    Hi Jacob

    I am using your json code in my project, I’ll add a description to your Wiki when I get it all working sensably. Looking at your code is an education. I thought I was an expert in Fortran (started in 1972) but, wow, was I ever wrong about that! 2 Questions:

    *   Is there a way I can report problems that I discover?

    *   Can the json format be adapted to include units information? I would like to be able to say (the equivalent of) “length”: 44.55 metres.

  3. Jacob says:

    The answer to both is yes:

    * You can submit an issue at the GitHub site.

    * You can put any data you want in a JSON structure. For units, I usually do something like this:

    {“length”: { “value”: 44.55, “units”: “meters”} }

Leave a Reply

Your email address will not be published. Required fields are marked *