jonquil_parser Module

JSON parser implementation.

This module provides procedures for parsing JSON documents into TOML Fortran data structures. It reuses the TOML Fortran parser infrastructure with a custom JSON lexer.

Main Interfaces

Example

use jonquil, only : json_loads, json_value, json_object, json_error, &
   & cast_to_object, get_value
class(json_value), allocatable :: val
type(json_object), pointer :: obj
type(json_error), allocatable :: error
integer :: num

call json_loads(val, '{"count": 42}', error=error)
obj => cast_to_object(val)
call get_value(obj, "count", num)
print '(a,i0)', "count = ", num


Interfaces

public interface json_load

Load a TOML data structure from the provided source

  • private subroutine json_load_file(object, filename, config, context, error)

    Load TOML data structure from file

    Arguments

    Type IntentOptional Attributes Name
    class(toml_value), intent(out), allocatable :: object

    Instance of the TOML data structure, not allocated in case of error

    character(kind=tfc, len=*), intent(in) :: filename

    Name of the file to load

    type(toml_parser_config), intent(in), optional :: config

    Configuration for the parser

    type(toml_context), intent(out), optional :: context

    Context tracking the origin of the data structure to allow rich reports

    type(toml_error), intent(out), optional, allocatable :: error

    Error handling, provides detailed diagnostic in case of error

  • private subroutine json_load_unit(object, io, config, context, error)

    Load TOML data structure from unit

    Arguments

    Type IntentOptional Attributes Name
    class(toml_value), intent(out), allocatable :: object

    Instance of the TOML data structure, not allocated in case of error

    integer, intent(in) :: io

    Unit to read from

    type(toml_parser_config), intent(in), optional :: config

    Configuration for the parser

    type(toml_context), intent(out), optional :: context

    Context tracking the origin of the data structure to allow rich reports

    type(toml_error), intent(out), optional, allocatable :: error

    Error handling, provides detailed diagnostic in case of error

public interface json_loads

Load a TOML data structure from a string

  • private subroutine json_load_string(object, string, config, context, error)

    Load TOML data structure from string

    Arguments

    Type IntentOptional Attributes Name
    class(toml_value), intent(out), allocatable :: object

    Instance of the TOML data structure, not allocated in case of error

    character(kind=tfc, len=*), intent(in) :: string

    String containing TOML document

    type(toml_parser_config), intent(in), optional :: config

    Configuration for the parser

    type(toml_context), intent(out), optional :: context

    Context tracking the origin of the data structure to allow rich reports

    type(toml_error), intent(out), optional, allocatable :: error

    Error handling, provides detailed diagnostic in case of error