fortplot_spec_json_reader Module

Low-level JSON token readers and I/O utilities.

Provides character-level JSON parsing primitives: whitespace skipping, string/number/bool reading, and value skipping. Also provides stdin and file reading utilities.



Functions

public function expect_char(json, pos, ch) result(ok)

Expect and consume a specific character

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: json
integer, intent(inout) :: pos
character(len=1), intent(in) :: ch

Return Value logical


Subroutines

public subroutine skip_ws(json, pos)

Skip whitespace characters

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: json
integer, intent(inout) :: pos

public subroutine read_string(json, pos, val, status)

Read a JSON quoted string, advancing pos past closing quote. Unescapes standard JSON escape sequences.

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: json
integer, intent(inout) :: pos
character(len=:), intent(out), allocatable :: val
integer, intent(out) :: status

public subroutine read_real(json, pos, val, status)

Read a JSON number as real(wp). Recognises JSON null and maps it to IEEE NaN.

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: json
integer, intent(inout) :: pos
real(kind=wp), intent(out) :: val
integer, intent(out) :: status

public subroutine read_int(json, pos, val, status)

Read a JSON integer

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: json
integer, intent(inout) :: pos
integer, intent(out) :: val
integer, intent(out) :: status

public subroutine read_bool(json, pos, val, status)

Read a JSON boolean (true/false)

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: json
integer, intent(inout) :: pos
logical, intent(out) :: val
integer, intent(out) :: status

public subroutine read_literal(json, pos, val, status)

Read an arbitrary JSON value as a literal string. For strings returns the quoted content; for numbers, booleans, null returns the raw text.

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: json
integer, intent(inout) :: pos
character(len=:), intent(out), allocatable :: val
integer, intent(out) :: status

public subroutine skip_value(json, pos)

Skip an arbitrary JSON value (string, number, bool, null, object, or array) without storing it.

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: json
integer, intent(inout) :: pos

public subroutine read_stdin(content, status)

Read entire stdin into a single string

Arguments

Type IntentOptional Attributes Name
character(len=:), intent(out), allocatable :: content
integer, intent(out) :: status

public subroutine read_file(filename, content, status)

Read entire file into a single string

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: filename
character(len=:), intent(out), allocatable :: content
integer, intent(out) :: status