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": [
      0.1E+1,
      0.2E+1,
      0.3E+1
    ]
  },
  "outputs": {
    "t": 0.1E+2,
    "x": [
      0.11E+2,
      0.22E+2,
      0.33E+3
    ]
  }
}

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.

Posted in Programming Tagged with: ,
One comment 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).

    Cheers

Leave a Reply

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

*