Need help with your JSON?

Try our JSON Formatter tool to automatically identify and fix syntax errors in your JSON. JSON Formatter tool

Fortran JSON Interface Libraries for Scientific Computing

If you are choosing a Fortran JSON library today, `json-fortran` is usually the default pick for new work: it has current releases, modern Fortran APIs, packaging options, and strong documentation. `FSON` still matters when you are maintaining older Fortran 95 style code or want a smaller, pointer-based parser for lightweight configuration files.

That distinction matters in scientific computing. Most teams do not need JSON for bulk numeric arrays, but they often do need a reliable way to load run configuration, emit metadata, exchange settings with Python or web tools, and validate small structured payloads without adding fragile ad hoc parsers.

Quick Recommendation

Choose `json-fortran` when

  • You are starting a new scientific application or modernizing an older one.
  • You want read and write support, not just a parser.
  • You need a documented API around `json_file` and `json_core` objects.
  • You care about current packaging options such as CMake, fpm, Conda, or Homebrew.

Choose `FSON` when

  • You are working inside a legacy codebase that is closer to Fortran 95.
  • You want a small DOM-style parser with path-based lookups.
  • You mostly read configuration or metadata rather than generate complex JSON output.
  • You prefer a lighter dependency surface and are comfortable with pointer-based cleanup.

What Scientific Users Usually Need

Search visitors landing on this topic are usually not looking for a generic definition of JSON. They need to answer a practical question: which library will fit the build system, compiler level, and data flow of my scientific code?

  • Predictable configuration loading: simulation inputs, solver settings, and experiment metadata should be easy to validate and easy to diff in version control.
  • Interop with other tools: JSON is useful when Python, web dashboards, CLI wrappers, or job schedulers need to exchange small structured payloads with Fortran.
  • Build compatibility: compiler support for Fortran 2003/2008 features can determine whether a modern library is painless or frustrating to adopt.
  • Reasonable failure modes: clear parse errors and explicit missing-key checks save time when debugging production runs.

Current Fortran JSON Library Landscape

In practice, most Fortran users comparing general-purpose JSON libraries still end up choosing between `json-fortran` and `FSON`. They overlap, but they are not aimed at exactly the same codebases.

LibraryWhat it gives youBuild and compatibility notesBest fit
json-fortranModern object-oriented API for parsing, querying, modifying, and serializing JSON. Official docs also call out thread safety and richer control over parser behavior.Current official GitHub release is 9.2.1 from February 22, 2026. The project documents CMake and fpm builds plus Conda and Homebrew packages. It expects a compiler with key Fortran 2003/2008 support.New scientific code, reusable libraries, and projects that need both read and write support.
FSONA Fortran 95 JSON parser built around `type(fson_value), pointer` trees and `fson_get` path lookups such as `mesh.cells` or `materials[1].name`.The current README documents Makefile, Meson, and CMake installation flows. Its design is simpler and closer to older Fortran styles, but that also means less modern ergonomics than `json-fortran`.Legacy HPC codebases, smaller config readers, and gradual modernization work.

`json-fortran`

This is the safest recommendation for most new work. The project exposes a higher-level `json_file` API, supports both parsing and generation, and is actively documented. If your team already uses fpm or CMake, adoption is straightforward.

Practical takeaway: if you need a library that feels maintained and ready for current tooling, start here.

`FSON`

`FSON` is still useful when you want a compact parser with direct path-based extraction and minimal abstraction. It is a better match for older code that is not ready to lean on more modern Fortran features.

Practical takeaway: strong option for legacy integration, but usually not the first choice for a new codebase.

Example: Reading Simulation Config with `json-fortran`

The modern `json-fortran` workflow is usually: initialize the object, load a file or string, retrieve values by path, then clean up. This is much closer to what most production scientific applications need than a purely conceptual parser example.

program read_config
  use json_module, only: json_file, json_RK
  implicit none

  type(json_file) :: json
  character(len=:), allocatable :: solver
  integer :: steps
  real(json_RK) :: dt
  logical :: found

  call json%initialize(compact_reals=.true.)
  call json%load(filename="config.json")

  call json%get("simulation.solver", solver, found)
  if (.not. found) error stop "Missing simulation.solver"

  call json%get("simulation.steps", steps, found)
  if (.not. found) error stop "Missing simulation.steps"

  call json%get("simulation.dt", dt, found)
  if (.not. found) error stop "Missing simulation.dt"

  print "(A,1X,A)", "solver:", solver
  print "(A,1X,I0)", "steps:", steps
  print "(A,1X,ES12.5)", "dt:", dt

  call json%destroy()
end program read_config

Two details matter here for real projects: the `found` flag lets you fail fast on missing keys, and the allocatable string avoids the silent truncation problems that fixed-length strings can introduce in legacy Fortran code.

Example: Lightweight Config Reads with `FSON`

`FSON` is attractive when you want direct path-based extraction and a smaller mental model. The path syntax is one of its most useful features for simple configuration files.

program read_input
  use fson
  implicit none

  type(fson_value), pointer :: cfg
  integer :: cells
  character(len=16) :: scheme

  cfg => fson_parse("input.json")

  call fson_get(cfg, "mesh.cells", cells)
  call fson_get(cfg, "solver.scheme", scheme)

  print *, "cells =", cells
  print *, "scheme =", trim(scheme)

  call fson_destroy(cfg)
end program read_input

That simplicity is useful, but remember that `FSON` is built around pointer-managed values. In long-running scientific applications, cleanup discipline still matters.

Build and Integration Notes

  • `json-fortran`: current docs and README cover CMake and fpm, and the project also publishes Conda and Homebrew installation routes. That makes it easier to standardize across developer machines and CI.
  • Compiler expectations: `json-fortran` depends on major Fortran 2003/2008 language features, so very old compiler stacks can be the deciding factor against it.
  • `FSON`: the README documents Makefile, Meson, and CMake flows. It can be a cleaner fit when you want to drop a parser into an older build without adopting a more feature-rich framework.
  • Interface shape: prefer `json-fortran` if you need to create and emit JSON, not just read it. Prefer `FSON` if simple extraction is the whole job.

Scientific Computing Caveats

  • Use JSON for metadata, not heavy numerics: configuration, provenance, model settings, and service payloads are good fits. Huge dense arrays and checkpoints usually belong in HDF5 or NetCDF instead.
  • Be explicit about missing keys: scientific runs should fail early when required parameters are absent or typed incorrectly.
  • Watch string handling: allocatable strings are safer than fixed-length buffers when file contents are controlled by external tooling.
  • Validate input before you debug Fortran: formatting and checking JSON first often exposes trailing commas, broken quoting, or malformed nesting faster than recompiling parser code.

If your real problem is broken input rather than library choice, run the payload through a JSON formatter first. Normalizing indentation and structure makes it much easier to see whether the bug is in the file or in your Fortran-side extraction logic.

Official References

These primary sources are the most useful starting points when you need current details beyond this guide:

Need help with your JSON?

Try our JSON Formatter tool to automatically identify and fix syntax errors in your JSON. JSON Formatter tool