To access the core routines for manipulation of json_value pointer variables. This class allows for thread safe use of the module.
program test
use json_module, wp=>json_RK
implicit none
type(json_core) :: json !<--have to declare this
type(json_value),pointer :: p
call json%create_object(p,'') !create the root
call json%add(p,'year',1805) !add some data
call json%add(p,'value',1.0_wp) !add some data
call json%print(p,'test.json') !write it to a file
call json%destroy(p) !cleanup
end program test
Type | Visibility | Attributes | Name | Initial | |||
---|---|---|---|---|---|---|---|
logical(kind=LK), | private | :: | allow_comments | = | .true. |
if true, any comments will be ignored when
parsing a file. The comment tokens are defined
by the |
|
logical(kind=LK), | private | :: | allow_duplicate_keys | = | .true. |
If False, then after parsing, if any duplicate keys are found, an error is thrown. A call to json_value_validate will also check for duplicates. If True [default] then no special checks are done |
|
logical(kind=LK), | private | :: | case_sensitive_keys | = | .true. |
if name and path comparisons are case sensitive. |
|
integer(kind=IK), | private | :: | char_count | = | 0 |
character position in the current line |
|
character(kind=CK, len=:), | private, | allocatable | :: | chunk |
a chunk read from a stream file
when |
||
character(kind=CK, len=:), | private, | allocatable | :: | comment_char |
comment tokens when
|
||
logical(kind=LK), | private | :: | compact_real | = | .true. |
to use the “compact” form of real numbers for output |
|
logical(kind=LK), | private | :: | compress_vectors | = | .false. |
If true, then arrays of integers,
nulls, reals, & logicals are
printed all on one line.
[Note: |
|
character(kind=CK, len=:), | private, | allocatable | :: | err_message |
the error message.
if |
||
logical(kind=LK), | private | :: | escape_solidus | = | .false. |
If True then the solidus “ |
|
logical(kind=LK), | private | :: | exception_thrown | = | .false. |
The error flag. Will be set to true when an error is thrown in the class. Many of the methods will check this and return immediately if it is true. |
|
integer, | private | :: | filesize | = | 0 |
the file size when when |
|
integer, | private | :: | ichunk | = | 0 |
index in |
|
integer(kind=IK), | private | :: | ipos | = | 1 |
for allocatable strings: next character to read |
|
logical(kind=LK), | private | :: | is_verbose | = | .false. |
if true, all exceptions are immediately printed to console. |
|
integer(kind=IK), | private | :: | line_count | = | 1 |
lines read counter |
|
logical(kind=LK), | private | :: | no_whitespace | = | .false. |
when printing a JSON string, don’t include non-significant spaces or line breaks. If true, the entire structure will be printed on one line. |
|
logical(kind=LK), | private | :: | non_normals_to_null | = | .false. |
How to serialize NaN, Infinity, and -Infinity real values:
|
|
integer(kind=IK), | private | :: | null_to_real_mode | = | 2_IK |
if
|
|
integer(kind=IK), | private | :: | path_mode | = | 1_IK |
How the path strings are interpreted in the
|
|
character(kind=CK, len=1), | private | :: | path_separator | = | dot |
The |
|
character(kind=CK, len=pushed_char_size), | private | :: | pushed_char | = | CK_'' |
used when parsing lines in file |
|
integer(kind=IK), | private | :: | pushed_index | = | 0 |
used when parsing lines in file |
|
character(kind=CDK, len=:), | private, | allocatable | :: | real_fmt |
the format string to use
for converting real numbers to strings.
It can be set in json_initialize,
and used in json_value_print
If not set, then |
||
integer(kind=IK), | private | :: | spaces_per_tab | = | 2 |
number of spaces for indenting |
|
logical(kind=LK), | private | :: | stop_on_error | = | .false. |
if true, then the program is stopped immediately when an exception is raised. |
|
logical(kind=LK), | private | :: | strict_integer_type_checking | = | .true. |
|
|
logical(kind=LK), | private | :: | strict_type_checking | = | .false. |
if true, then no type conversions are done
in the |
|
logical(kind=LK), | private | :: | trailing_spaces_significant | = | .false. |
for name and path comparisons, if trailing space is to be considered significant. |
|
logical(kind=LK), | private | :: | unescaped_strings | = | .true. |
If false, then the escaped string is returned from json_get_string and similar routines. If true [default], then the string is returned unescaped. |
|
logical(kind=LK), | private | :: | use_quiet_nan | = | .true. |
if true [default], |
Structure constructor to initialize a json_core object
type(json_file) :: json_core
json_core = json_core()
Function constructor for a json_core. This is just a wrapper for json_initialize.
initialize_json_core, json_initialize, initialize_json_core_in_file, and initialize_json_file all have a similar interface.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
logical(kind=LK), | intent(in), | optional | :: | verbose |
mainly useful for debugging (default is false) |
|
logical(kind=LK), | intent(in), | optional | :: | compact_reals |
to compact the real number strings for output (default is true) |
|
logical(kind=LK), | intent(in), | optional | :: | print_signs |
always print numeric sign (default is false) |
|
character(kind=CDK, len=*), | intent(in), | optional | :: | real_format |
Real number format: ‘E’ [default], ‘*’, ‘G’, ‘EN’, or ‘ES’ |
|
integer(kind=IK), | intent(in), | optional | :: | spaces_per_tab |
number of spaces per tab for indenting (default is 2) |
|
logical(kind=LK), | intent(in), | optional | :: | strict_type_checking |
if true, no integer, double, or logical type
conversions are done for the |
|
logical(kind=LK), | intent(in), | optional | :: | trailing_spaces_significant |
for name and path comparisons, is trailing space to be considered significant. (default is false) |
|
logical(kind=LK), | intent(in), | optional | :: | case_sensitive_keys |
for name and path comparisons, are they case sensitive. (default is true) |
|
logical(kind=LK), | intent(in), | optional | :: | no_whitespace |
if true, printing the JSON structure is done without adding any non-significant spaces or linebreaks (default is false) |
|
logical(kind=LK), | intent(in), | optional | :: | unescape_strings |
If false, then the raw escaped string is returned from json_get_string and similar routines. If true [default], then the string is returned unescaped. |
|
character(kind=CK, len=*), | intent(in), | optional | :: | comment_char |
If present, these characters are used
to denote comments in the JSON file,
which will be ignored if present.
Example: |
|
integer(kind=IK), | intent(in), | optional | :: | path_mode |
How the path strings are interpreted in the
|
|
character(kind=CK, len=1), | intent(in), | optional | :: | path_separator |
The |
|
logical(kind=LK), | intent(in), | optional | :: | compress_vectors |
If true, then arrays of integers,
nulls, doubles, and logicals are
printed all on one line.
[Note: |
|
logical(kind=LK), | intent(in), | optional | :: | allow_duplicate_keys |
|
|
logical(kind=LK), | intent(in), | optional | :: | escape_solidus |
Note that this option does not affect parsing (both escaped and unescaped are still valid in all cases). |
|
logical(kind=LK), | intent(in), | optional | :: | stop_on_error |
If an exception is raised, then immediately quit. (Default is False). |
|
integer(kind=IK), | intent(in), | optional | :: | null_to_real_mode |
if |
|
integer(kind=IK), | intent(in), | optional | :: | non_normal_mode |
How to serialize NaN, Infinity, and -Infinity real values: |
|
logical(kind=LK), | intent(in), | optional | :: | use_quiet_nan |
|
|
logical(kind=LK), | intent(in), | optional | :: | strict_integer_type_checking |
(default is true) |
Add objects to a linked list of json_values.
It might make more sense to call this add_child
.
Adds member
as a child of p
.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p |
|
||
type(json_value), | pointer | :: | member |
the child member
to add to |
Add a NULL value child to the json_value variable.
This routine is part of the public API that can be used to build a JSON structure using json_value pointers.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p | |||
character(kind=CK, len=*), | intent(in) | :: | name |
Alternate version of json_value_add_null where name
is kind=CDK.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p | |||
character(kind=CDK, len=*), | intent(in) | :: | name |
name of the variable |
Add an integer value child to the json_value variable.
This routine is part of the public API that can be used to build a JSON structure using json_value pointers.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p | |||
character(kind=CK, len=*), | intent(in) | :: | name | |||
integer(kind=IK), | intent(in) | :: | val |
Alternate version of json_value_add_integer where name
is kind=CDK.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p | |||
character(kind=CDK, len=*), | intent(in) | :: | name |
name of the variable |
||
integer(kind=IK), | intent(in) | :: | val |
value |
Add a integer vector child to the json_value variable.
This routine is part of the public API that can be used to build a JSON structure using json_value pointers.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p | |||
character(kind=CK, len=*), | intent(in) | :: | name |
name of the variable |
||
integer(kind=IK), | intent(in), | dimension(:) | :: | val |
value |
Alternate version of json_value_add_integer_vec where name
is kind=CDK.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p | |||
character(kind=CDK, len=*), | intent(in) | :: | name |
name of the variable |
||
integer(kind=IK), | intent(in), | dimension(:) | :: | val |
value |
Alternate version of json_value_add_real where val
is real32
.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p | |||
character(kind=CK, len=*), | intent(in) | :: | name |
variable name |
||
real(kind=real32), | intent(in) | :: | val |
real value |
Alternate version of json_value_add_real32 where name
is kind=CDK.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p | |||
character(kind=CDK, len=*), | intent(in) | :: | name |
variable name |
||
real(kind=real32), | intent(in) | :: | val |
real value |
Alternate version of json_value_add_real_vec where val
is real32
.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p | |||
character(kind=CK, len=*), | intent(in) | :: | name | |||
real(kind=real32), | intent(in), | dimension(:) | :: | val |
Alternate version of json_value_add_real32_vec where name
is kind=CDK.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p | |||
character(kind=CDK, len=*), | intent(in) | :: | name | |||
real(kind=real32), | intent(in), | dimension(:) | :: | val |
Add a real value child to the json_value variable.
This routine is part of the public API that can be used to build a JSON structure using json_value pointers.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p | |||
character(kind=CK, len=*), | intent(in) | :: | name |
variable name |
||
real(kind=RK), | intent(in) | :: | val |
real value |
Alternate version of json_value_add_real where name
is kind=CDK.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p | |||
character(kind=CDK, len=*), | intent(in) | :: | name |
variable name |
||
real(kind=RK), | intent(in) | :: | val |
real value |
Add a real vector child to the json_value variable.
This routine is part of the public API that can be used to build a JSON structure using json_value pointers.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p | |||
character(kind=CK, len=*), | intent(in) | :: | name | |||
real(kind=RK), | intent(in), | dimension(:) | :: | val |
Alternate version of json_value_add_real_vec where name
is kind=CDK.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p | |||
character(kind=CDK, len=*), | intent(in) | :: | name | |||
real(kind=RK), | intent(in), | dimension(:) | :: | val |
Add a logical value child to the json_value variable.
This routine is part of the public API that can be used to build a JSON structure using json_value pointers.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p | |||
character(kind=CK, len=*), | intent(in) | :: | name |
name of the variable |
||
logical(kind=LK), | intent(in) | :: | val |
value |
Alternate version of json_value_add_logical where name
is kind=CDK.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p | |||
character(kind=CDK, len=*), | intent(in) | :: | name |
name of the variable |
||
logical(kind=LK), | intent(in) | :: | val |
value |
Add a logical vector child to the json_value variable.
This routine is part of the public API that can be used to build a JSON structure using json_value pointers.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p | |||
character(kind=CK, len=*), | intent(in) | :: | name |
name of the vector |
||
logical(kind=LK), | intent(in), | dimension(:) | :: | val |
value |
Alternate version of json_value_add_logical_vec where name
is kind=CDK.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p | |||
character(kind=CDK, len=*), | intent(in) | :: | name |
name of the variable |
||
logical(kind=LK), | intent(in), | dimension(:) | :: | val |
value |
Add a character string child to the json_value variable.
This routine is part of the public API that can be used to build a JSON structure using json_value pointers.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p | |||
character(kind=CK, len=*), | intent(in) | :: | name |
name of the variable |
||
character(kind=CK, len=*), | intent(in) | :: | val |
value |
||
logical(kind=LK), | intent(in), | optional | :: | trim_str |
if TRIM() should be called for the |
|
logical(kind=LK), | intent(in), | optional | :: | adjustl_str |
if ADJUSTL() should be called for the |
Alternate version of json_value_add_string where name
and val
are kind=CDK.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p | |||
character(kind=CDK, len=*), | intent(in) | :: | name |
name of the variable |
||
character(kind=CDK, len=*), | intent(in) | :: | val |
value |
||
logical(kind=LK), | intent(in), | optional | :: | trim_str |
if TRIM() should be called for the |
|
logical(kind=LK), | intent(in), | optional | :: | adjustl_str |
if ADJUSTL() should be called for the |
Add a character string vector child to the json_value variable.
This routine is part of the public API that can be used to build a JSON structure using json_value pointers.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p | |||
character(kind=CK, len=*), | intent(in) | :: | name |
variable name |
||
character(kind=CK, len=*), | intent(in), | dimension(:) | :: | val |
array of strings |
|
logical(kind=LK), | intent(in), | optional | :: | trim_str |
if TRIM() should be called for each element |
|
logical(kind=LK), | intent(in), | optional | :: | adjustl_str |
if ADJUSTL() should be called for each element |
Alternate version of json_value_add_string_vec where name
and val
are kind=CDK.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p | |||
character(kind=CDK, len=*), | intent(in) | :: | name | |||
character(kind=CDK, len=*), | intent(in), | dimension(:) | :: | val | ||
logical(kind=LK), | intent(in), | optional | :: | trim_str | ||
logical(kind=LK), | intent(in), | optional | :: | adjustl_str |
Alternate version of json_value_add_string where name
is kind=CDK.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p | |||
character(kind=CDK, len=*), | intent(in) | :: | name |
name of the variable |
||
character(kind=CK, len=*), | intent(in) | :: | val |
value |
||
logical(kind=LK), | intent(in), | optional | :: | trim_str |
if TRIM() should be called for the |
|
logical(kind=LK), | intent(in), | optional | :: | adjustl_str |
if ADJUSTL() should be called for the |
Alternate version of json_value_add_string where val
is kind=CDK.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p | |||
character(kind=CK, len=*), | intent(in) | :: | name |
name of the variable |
||
character(kind=CDK, len=*), | intent(in) | :: | val |
value |
||
logical(kind=LK), | intent(in), | optional | :: | trim_str |
if TRIM() should be called for the |
|
logical(kind=LK), | intent(in), | optional | :: | adjustl_str |
if ADJUSTL() should be called for the |
Alternate version of json_value_add_string_vec where name
is kind=CDK.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p | |||
character(kind=CDK, len=*), | intent(in) | :: | name | |||
character(kind=CK, len=*), | intent(in), | dimension(:) | :: | val | ||
logical(kind=LK), | intent(in), | optional | :: | trim_str | ||
logical(kind=LK), | intent(in), | optional | :: | adjustl_str |
Alternate version of json_value_add_string_vec where val
is kind=CDK.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p | |||
character(kind=CK, len=*), | intent(in) | :: | name | |||
character(kind=CDK, len=*), | intent(in), | dimension(:) | :: | val | ||
logical(kind=LK), | intent(in), | optional | :: | trim_str | ||
logical(kind=LK), | intent(in), | optional | :: | adjustl_str |
Add variables to a json_value linked list by specifying their paths.
use, intrinsic :: iso_fortran_env, only: output_unit
use json_module, wp=>json_RK
type(json_core) :: json
type(json_value) :: p
call json%create_object(p,'root') ! create the root
! now add some variables using the paths:
call json%add_by_path(p,'inputs.t', 0.0_wp )
call json%add_by_path(p,'inputs.x(1)', 100.0_wp)
call json%add_by_path(p,'inputs.x(2)', 200.0_wp)
call json%print(p) ! now print to console
json_core%update
methods.Add a new member (json_value
pointer) to a JSON structure, given the path.
If the path points to an existing variable in the structure, then this routine will destroy it and replace it with the new value.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | me |
the JSON structure |
||
character(kind=CK, len=*), | intent(in) | :: | path |
the path to the variable |
||
type(json_value), | intent(in), | pointer | :: | p |
the value to add |
|
logical(kind=LK), | intent(out), | optional | :: | found |
if the variable was found |
|
logical(kind=LK), | intent(out), | optional | :: | was_created |
if the variable had to be created |
Wrapper to json_add_member_by_path where “path” is kind=CDK.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | me |
the JSON structure |
||
character(kind=CDK, len=*), | intent(in) | :: | path |
the path to the variable |
||
type(json_value), | intent(in), | pointer | :: | p |
the value to add |
|
logical(kind=LK), | intent(out), | optional | :: | found |
if the variable was found |
|
logical(kind=LK), | intent(out), | optional | :: | was_created |
if the variable had to be created |
Add an integer value to a json_value, given the path.
If the path points to an existing variable in the structure, then this routine will destroy it and replace it with the new value.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | me |
the JSON structure |
||
character(kind=CK, len=*), | intent(in) | :: | path |
the path to the variable |
||
integer(kind=IK), | intent(in) | :: | value |
the value to add |
||
logical(kind=LK), | intent(out), | optional | :: | found |
if the variable was found |
|
logical(kind=LK), | intent(out), | optional | :: | was_created |
if the variable had to be created |
Wrapper to json_add_integer_by_path where “path” is kind=CDK.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | me |
the JSON structure |
||
character(kind=CDK, len=*), | intent(in) | :: | path |
the path to the variable |
||
integer(kind=IK), | intent(in) | :: | value |
the value to add |
||
logical(kind=LK), | intent(out), | optional | :: | found |
if the variable was found |
|
logical(kind=LK), | intent(out), | optional | :: | was_created |
if the variable had to be created |
Alternate version of json_add_real_by_path where value=real32.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | me |
the JSON structure |
||
character(kind=CK, len=*), | intent(in) | :: | path |
the path to the variable |
||
real(kind=real32), | intent(in) | :: | value |
the value to add |
||
logical(kind=LK), | intent(out), | optional | :: | found |
if the variable was found |
|
logical(kind=LK), | intent(out), | optional | :: | was_created |
if the variable had to be created |
Wrapper to json_add_real32_by_path where “path” is kind=CDK.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | me |
the JSON structure |
||
character(kind=CDK, len=*), | intent(in) | :: | path |
the path to the variable |
||
real(kind=real32), | intent(in) | :: | value |
the value to add |
||
logical(kind=LK), | intent(out), | optional | :: | found |
if the variable was found |
|
logical(kind=LK), | intent(out), | optional | :: | was_created |
if the variable had to be created |
Add an real value to a json_value, given the path.
If the path points to an existing variable in the structure, then this routine will destroy it and replace it with the new value.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | me |
the JSON structure |
||
character(kind=CK, len=*), | intent(in) | :: | path |
the path to the variable |
||
real(kind=RK), | intent(in) | :: | value |
the value to add |
||
logical(kind=LK), | intent(out), | optional | :: | found |
if the variable was found |
|
logical(kind=LK), | intent(out), | optional | :: | was_created |
if the variable had to be created |
Wrapper to json_add_real_by_path where “path” is kind=CDK.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | me |
the JSON structure |
||
character(kind=CDK, len=*), | intent(in) | :: | path |
the path to the variable |
||
real(kind=RK), | intent(in) | :: | value |
the value to add |
||
logical(kind=LK), | intent(out), | optional | :: | found |
if the variable was found |
|
logical(kind=LK), | intent(out), | optional | :: | was_created |
if the variable had to be created |
Add a logical value to a json_value, given the path.
If the path points to an existing variable in the structure, then this routine will destroy it and replace it with the new value.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | me |
the JSON structure |
||
character(kind=CK, len=*), | intent(in) | :: | path |
the path to the variable |
||
logical(kind=LK), | intent(in) | :: | value |
the value to add |
||
logical(kind=LK), | intent(out), | optional | :: | found |
if the variable was found |
|
logical(kind=LK), | intent(out), | optional | :: | was_created |
if the variable had to be created |
Wrapper to json_add_logical_by_path where “path” is kind=CDK.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | me |
the JSON structure |
||
character(kind=CDK, len=*), | intent(in) | :: | path |
the path to the variable |
||
logical(kind=LK), | intent(in) | :: | value |
the value to add |
||
logical(kind=LK), | intent(out), | optional | :: | found |
if the variable was found |
|
logical(kind=LK), | intent(out), | optional | :: | was_created |
if the variable had to be created |
Add a string value to a json_value, given the path.
If the path points to an existing variable in the structure, then this routine will destroy it and replace it with the new value.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | me |
the JSON structure |
||
character(kind=CK, len=*), | intent(in) | :: | path |
the path to the variable |
||
character(kind=CK, len=*), | intent(in) | :: | value |
the value to add |
||
logical(kind=LK), | intent(out), | optional | :: | found |
if the variable was found |
|
logical(kind=LK), | intent(out), | optional | :: | was_created |
if the variable had to be created |
|
logical(kind=LK), | intent(in), | optional | :: | trim_str |
if TRIM() should be called for each element |
|
logical(kind=LK), | intent(in), | optional | :: | adjustl_str |
if ADJUSTL() should be called for each element |
Wrapper to json_add_string_by_path where “path” is kind=CDK.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | me |
the JSON structure |
||
character(kind=CDK, len=*), | intent(in) | :: | path |
the path to the variable |
||
character(kind=CDK, len=*), | intent(in) | :: | value |
the value to add |
||
logical(kind=LK), | intent(out), | optional | :: | found |
if the variable was found |
|
logical(kind=LK), | intent(out), | optional | :: | was_created |
if the variable had to be created |
|
logical(kind=LK), | intent(in), | optional | :: | trim_str |
if TRIM() should be called for each element |
|
logical(kind=LK), | intent(in), | optional | :: | adjustl_str |
if ADJUSTL() should be called for each element |
Wrapper to json_add_integer_by_path for adding an integer vector by path.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | me |
the JSON structure |
||
character(kind=CK, len=*), | intent(in) | :: | path |
the path to the variable |
||
integer(kind=IK), | intent(in), | dimension(:) | :: | value |
the vector to add |
|
logical(kind=LK), | intent(out), | optional | :: | found |
if the variable was found |
|
logical(kind=LK), | intent(out), | optional | :: | was_created |
if the variable had to be created |
Wrapper for json_add_integer_vec_by_path where “path” is kind=CDK).
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | me |
the JSON structure |
||
character(kind=CDK, len=*), | intent(in) | :: | path |
the path to the variable |
||
integer(kind=IK), | intent(in), | dimension(:) | :: | value |
the vector to add |
|
logical(kind=LK), | intent(out), | optional | :: | found |
if the variable was found |
|
logical(kind=LK), | intent(out), | optional | :: | was_created |
if the variable had to be created |
Wrapper to json_add_real_by_path for adding a real vector by path.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | me |
the JSON structure |
||
character(kind=CK, len=*), | intent(in) | :: | path |
the path to the variable |
||
real(kind=real32), | intent(in), | dimension(:) | :: | value |
the vector to add |
|
logical(kind=LK), | intent(out), | optional | :: | found |
if the variable was found |
|
logical(kind=LK), | intent(out), | optional | :: | was_created |
if the variable had to be created |
Wrapper for json_add_real32_vec_by_path where “path” is kind=CDK).
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | me |
the JSON structure |
||
character(kind=CDK, len=*), | intent(in) | :: | path |
the path to the variable |
||
real(kind=real32), | intent(in), | dimension(:) | :: | value |
the vector to add |
|
logical(kind=LK), | intent(out), | optional | :: | found |
if the variable was found |
|
logical(kind=LK), | intent(out), | optional | :: | was_created |
if the variable had to be created |
Wrapper to json_add_real_by_path for adding a real vector by path.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | me |
the JSON structure |
||
character(kind=CK, len=*), | intent(in) | :: | path |
the path to the variable |
||
real(kind=RK), | intent(in), | dimension(:) | :: | value |
the vector to add |
|
logical(kind=LK), | intent(out), | optional | :: | found |
if the variable was found |
|
logical(kind=LK), | intent(out), | optional | :: | was_created |
if the variable had to be created |
Wrapper for json_add_real_vec_by_path where “path” is kind=CDK).
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | me |
the JSON structure |
||
character(kind=CDK, len=*), | intent(in) | :: | path |
the path to the variable |
||
real(kind=RK), | intent(in), | dimension(:) | :: | value |
the vector to add |
|
logical(kind=LK), | intent(out), | optional | :: | found |
if the variable was found |
|
logical(kind=LK), | intent(out), | optional | :: | was_created |
if the variable had to be created |
Wrapper to json_add_logical_by_path for adding a logical vector by path.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | me |
the JSON structure |
||
character(kind=CK, len=*), | intent(in) | :: | path |
the path to the variable |
||
logical(kind=LK), | intent(in), | dimension(:) | :: | value |
the vector to add |
|
logical(kind=LK), | intent(out), | optional | :: | found |
if the variable was found |
|
logical(kind=LK), | intent(out), | optional | :: | was_created |
if the variable had to be created |
Wrapper for json_add_logical_vec_by_path where “path” is kind=CDK).
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | me |
the JSON structure |
||
character(kind=CDK, len=*), | intent(in) | :: | path |
the path to the variable |
||
logical(kind=LK), | intent(in), | dimension(:) | :: | value |
the vector to add |
|
logical(kind=LK), | intent(out), | optional | :: | found |
if the variable was found |
|
logical(kind=LK), | intent(out), | optional | :: | was_created |
if the variable had to be created |
Wrapper to json_add_string_by_path for adding a string vector by path.
The ilen
input can be used to specify the actual lengths of the
the strings in the array. They must all be <= len(value)
.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | me |
the JSON structure |
||
character(kind=CK, len=*), | intent(in) | :: | path |
the path to the variable |
||
character(kind=CK, len=*), | intent(in), | dimension(:) | :: | value |
the vector to add |
|
logical(kind=LK), | intent(out), | optional | :: | found |
if the variable was found |
|
logical(kind=LK), | intent(out), | optional | :: | was_created |
if the variable had to be created |
|
integer(kind=IK), | intent(in), | optional, | dimension(:) | :: | ilen |
the string lengths of each
element in |
logical(kind=LK), | intent(in), | optional | :: | trim_str |
if TRIM() should be called for each element |
|
logical(kind=LK), | intent(in), | optional | :: | adjustl_str |
if ADJUSTL() should be called for each element |
Wrapper for json_add_string_vec_by_path where “path” and “value” are kind=CDK).
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | me |
the JSON structure |
||
character(kind=CDK, len=*), | intent(in) | :: | path |
the path to the variable |
||
character(kind=CDK, len=*), | intent(in), | dimension(:) | :: | value |
the vector to add |
|
logical(kind=LK), | intent(out), | optional | :: | found |
if the variable was found |
|
logical(kind=LK), | intent(out), | optional | :: | was_created |
if the variable had to be created |
|
integer(kind=IK), | intent(in), | optional, | dimension(:) | :: | ilen |
the string lengths of each
element in |
logical(kind=LK), | intent(in), | optional | :: | trim_str |
if TRIM() should be called for each element |
|
logical(kind=LK), | intent(in), | optional | :: | adjustl_str |
if ADJUSTL() should be called for each element |
Wrapper for json_add_string_by_path where “value” is kind=CDK.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | me |
the JSON structure |
||
character(kind=CK, len=*), | intent(in) | :: | path |
the path to the variable |
||
character(kind=CDK, len=*), | intent(in) | :: | value |
the value to add |
||
logical(kind=LK), | intent(out), | optional | :: | found |
if the variable was found |
|
logical(kind=LK), | intent(out), | optional | :: | was_created |
if the variable had to be created |
|
logical(kind=LK), | intent(in), | optional | :: | trim_str |
if TRIM() should be called for each element |
|
logical(kind=LK), | intent(in), | optional | :: | adjustl_str |
if ADJUSTL() should be called for each element |
Wrapper for json_add_string_by_path where “path” is kind=CDK.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | me |
the JSON structure |
||
character(kind=CDK, len=*), | intent(in) | :: | path |
the path to the variable |
||
character(kind=CK, len=*), | intent(in) | :: | value |
the value to add |
||
logical(kind=LK), | intent(out), | optional | :: | found |
if the variable was found |
|
logical(kind=LK), | intent(out), | optional | :: | was_created |
if the variable had to be created |
|
logical(kind=LK), | intent(in), | optional | :: | trim_str |
if TRIM() should be called for each element |
|
logical(kind=LK), | intent(in), | optional | :: | adjustl_str |
if ADJUSTL() should be called for each element |
Wrapper for json_add_string_vec_by_path where “value” is kind=CDK).
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | me |
the JSON structure |
||
character(kind=CK, len=*), | intent(in) | :: | path |
the path to the variable |
||
character(kind=CDK, len=*), | intent(in), | dimension(:) | :: | value |
the vector to add |
|
logical(kind=LK), | intent(out), | optional | :: | found |
if the variable was found |
|
logical(kind=LK), | intent(out), | optional | :: | was_created |
if the variable had to be created |
|
integer(kind=IK), | intent(in), | optional, | dimension(:) | :: | ilen |
the string lengths of each
element in |
logical(kind=LK), | intent(in), | optional | :: | trim_str |
if TRIM() should be called for each element |
|
logical(kind=LK), | intent(in), | optional | :: | adjustl_str |
if ADJUSTL() should be called for each element |
Wrapper for json_add_string_vec_by_path where “path” is kind=CDK).
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | me |
the JSON structure |
||
character(kind=CDK, len=*), | intent(in) | :: | path |
the path to the variable |
||
character(kind=CK, len=*), | intent(in), | dimension(:) | :: | value |
the vector to add |
|
logical(kind=LK), | intent(out), | optional | :: | found |
if the variable was found |
|
logical(kind=LK), | intent(out), | optional | :: | was_created |
if the variable had to be created |
|
integer(kind=IK), | intent(in), | optional, | dimension(:) | :: | ilen |
the string lengths of each
element in |
logical(kind=LK), | intent(in), | optional | :: | trim_str |
if TRIM() should be called for each element |
|
logical(kind=LK), | intent(in), | optional | :: | adjustl_str |
if ADJUSTL() should be called for each element |
Generate a warning message if there was an error parsing a JSON file or string.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
integer(kind=IK), | intent(in) | :: | iunit |
file unit number |
||
character(kind=CK, len=*), | intent(in) | :: | str |
string with JSON data |
Check a json_value
object’s
children for duplicate keys
Checks a JSON object for duplicate child names.
It uses the specified settings for name matching (see name_strings_equal).
This will only check for one duplicate, it will return the first one that it finds.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | intent(in), | pointer | :: | p |
the object to search. If |
|
logical(kind=LK), | intent(out) | :: | has_duplicate |
true if there is at least
two children have duplicate
|
||
character(kind=CK, len=:), | intent(out), | optional, | allocatable | :: | name |
the duplicate name (unallocated if no duplicate was found) |
character(kind=CK, len=:), | intent(out), | optional, | allocatable | :: | path |
the full path to the duplicate name (unallocated if no duplicate was found) |
Check entire JSON structure for duplicate keys (recursively)
Checks a JSON structure for duplicate child names. This one recursively traverses the entire structure (calling json_check_children_for_duplicate_keys recursively for each element).
This will only check for one duplicate, it will return the first one that it finds.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | intent(in), | pointer | :: | p |
the object to search. If |
|
logical(kind=LK), | intent(out) | :: | has_duplicate |
true if there is at least
one duplicate |
||
character(kind=CK, len=:), | intent(out), | optional, | allocatable | :: | name |
the duplicate name (unallocated if no duplicates were found) |
character(kind=CK, len=:), | intent(out), | optional, | allocatable | :: | path |
the full path to the duplicate name (unallocated if no duplicate was found) |
check for error and get error message
Retrieve error code from the json_core.
This should be called after parse
to check for errors.
If an error is thrown, before using the class again, json_initialize
should be called to clean up before it is used again.
type(json_file) :: json
logical :: status_ok
character(kind=CK,len=:),allocatable :: error_msg
call json%load(filename='myfile.json')
call json%check_for_errors(status_ok, error_msg)
if (.not. status_ok) then
write(*,*) 'Error: '//error_msg
call json%clear_exceptions()
call json%destroy()
end if
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(in) | :: | json | |||
logical(kind=LK), | intent(out), | optional | :: | status_ok |
true if there were no errors |
|
character(kind=CK, len=:), | intent(out), | optional, | allocatable | :: | error_msg |
the error message. (not allocated if there were no errors) |
clear exceptions
Clear exceptions in the json_core.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json |
clone a JSON structure (deep copy)
Create a deep copy of a json_value linked-list structure.
from
has children, then they are also cloned.from
is not linked to to
.from
is an element of an array, then the previous and
next entries are not cloned (only that element and it’s children, if any). program test
use json_module
implicit none
type(json_core) :: json
type(json_value),pointer :: j1, j2
call json%load('files/inputs/test1.json',j1)
call json%clone(j1,j2) !now have two independent copies
call json%destroy(j1) !destroys j1, but j2 remains
call json%print(j2,'j2.json')
call json%destroy(j2)
end program test
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | from |
this is the structure to clone |
||
type(json_value), | pointer | :: | to |
the clone is put here (it must not already be associated) |
Convert an existing JSON variable p
to a different variable type.
The existing variable (and its children) is destroyed. It is replaced
in the structure by a new variable of type var_type
(which can be a json_null
, json_object
or json_array
).
This is an internal routine used when creating variables by path.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p |
the variable to convert |
||
integer(kind=IK), | intent(in) | :: | var_type |
the variable type to convert |
count the number of children
Count the number of children in the object or array.
n_children
variable.
Renamed from json_value_count
.Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | intent(in), | pointer | :: | p |
this should normally be a |
number of children in p
.
Create a json_value linked list using the path to the variables. Optionally return a pointer to the variable.
(This will create a null
variable)
Returns the json_value pointer given the path string, If necessary, by creating the variables as needed.
By default, the leaf node and any empty array elements
are created as json_null
values.
It only works for path_mode=1
or path_mode=3
.
An error will be thrown for path_mode=2
(RFC 6901).
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | intent(in), | pointer | :: | me |
a JSON linked list |
|
character(kind=CK, len=*), | intent(in) | :: | path |
path to the variable |
||
type(json_value), | intent(out), | optional, | pointer | :: | p |
pointer to the variable
specify by |
logical(kind=LK), | intent(out), | optional | :: | found |
true if there were no errors (variable found or created) |
|
logical(kind=LK), | intent(out), | optional | :: | was_created |
true if it was actually created (as opposed to already being there) |
Alternate version of json_create_by_path where “path” is kind=CDK.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | intent(in), | pointer | :: | me |
a JSON linked list |
|
character(kind=CDK, len=*), | intent(in) | :: | path |
path to the variable |
||
type(json_value), | intent(out), | optional, | pointer | :: | p |
pointer to the variable
specify by |
logical(kind=LK), | intent(out), | optional | :: | found |
true if there were no errors (variable found or created) |
|
logical(kind=LK), | intent(out), | optional | :: | was_created |
true if it was actually created (as opposed to already being there) |
Allocate a json_value pointer and make it an array variable. The pointer should not already be allocated.
type(json_core) :: json
type(json_value),pointer :: p
call json%create_array(p,'arrayname')
Allocate a json_value pointer and make it an array variable. The pointer should not already be allocated.
type(json_value),pointer :: p
type(json_core) :: json
call json%create_array(p,'arrayname')
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p | |||
character(kind=CK, len=*), | intent(in) | :: | name |
A wrapper for json_value_create_array so that create_array
method may be
called with an actual argument, corresponding to the dummy argument name
,
that is either of ‘DEFAULT’ or ‘ISO_10646’ character kind.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p | |||
character(kind=CDK, len=*), | intent(in) | :: | name |
This is equivalent to create_real, and is here only for backward compatibility.
Allocate a json_value pointer and make it a real(RK) variable. The pointer should not already be allocated.
type(json_value),pointer :: p
type(json_core) :: json
call json%create_real(p,'value',1.0_RK)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p | |||
real(kind=RK), | intent(in) | :: | val | |||
character(kind=CK, len=*), | intent(in) | :: | name |
A wrapper for json_value_create_real so that create_real
method
may be called with an actual argument corresponding to the dummy argument,
name
that may be of ‘DEFAULT’ or ‘ISO_10646’ character kind.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p | |||
real(kind=RK), | intent(in) | :: | val | |||
character(kind=CDK, len=*), | intent(in) | :: | name |
Alternate version of json_value_create_real where val=real32.
The value is converted into a real(RK)
variable internally.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p | |||
real(kind=real32), | intent(in) | :: | val | |||
character(kind=CK, len=*), | intent(in) | :: | name |
Alternate version of json_value_create_real32 where “name” is kind(CDK).
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p | |||
real(kind=real32), | intent(in) | :: | val | |||
character(kind=CDK, len=*), | intent(in) | :: | name |
Allocate a json_value pointer and make it an integer variable. The pointer should not already be allocated.
type(json_core) :: json
type(json_value),pointer :: p
call json%create_integer(p,42,'value')
Allocate a json_value pointer and make it an integer(IK) variable. The pointer should not already be allocated.
type(json_value),pointer :: p
type(json_core) :: json
call json%create_integer(p,'value',1)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p | |||
integer(kind=IK), | intent(in) | :: | val | |||
character(kind=CK, len=*), | intent(in) | :: | name |
A wrapper procedure for json_value_create_integer so that create_integer
method may be called with either a ‘DEFAULT’ or ‘ISO_10646’ character kind
name
actual argument.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p | |||
integer(kind=IK), | intent(in) | :: | val | |||
character(kind=CDK, len=*), | intent(in) | :: | name |
Allocate a json_value pointer and make it a logical variable. The pointer should not already be allocated.
type(json_core) :: json
type(json_value),pointer :: p
call json%create_logical(p,'value',.true.)
Allocate a json_value pointer and make it a logical(LK) variable. The pointer should not already be allocated.
type(json_value),pointer :: p
type(json_core) :: json
call json%create_logical(p,'value',.true.)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p | |||
logical(kind=LK), | intent(in) | :: | val |
variable value |
||
character(kind=CK, len=*), | intent(in) | :: | name |
variable name |
Wrapper for json_value_create_logical so create_logical
method can
be called with name of character kind ‘DEFAULT’ or ‘ISO_10646’
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p | |||
logical(kind=LK), | intent(in) | :: | val | |||
character(kind=CDK, len=*), | intent(in) | :: | name |
Allocate a json_value pointer and make it a null variable. The pointer should not already be allocated.
type(json_core) :: json
type(json_value),pointer :: p
call json%create_null(p,'value')
Allocate a json_value pointer and make it a null variable. The pointer should not already be allocated.
type(json_value),pointer :: p
type(json_core) :: json
call json%create_null(p,'value')
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p | |||
character(kind=CK, len=*), | intent(in) | :: | name |
Wrap json_value_create_null so that create_null
method may be called with
an actual argument corresponding to the dummy argument name
that is either
of ‘DEFAULT’ or ‘ISO_10646’ character kind.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p | |||
character(kind=CDK, len=*), | intent(in) | :: | name |
Allocate a json_value pointer and make it an object variable. The pointer should not already be allocated.
type(json_core) :: json
type(json_value),pointer :: p
call json%create_object(p,'objectname')
The name is not significant for the root structure or an array element. In those cases, an empty string can be used.
Allocate a json_value pointer and make it an object variable. The pointer should not already be allocated.
type(json_value),pointer :: p
type(json_core) :: json
call json%create_object(p,'objectname')
The name is not significant for the root structure or an array element. In those cases, an empty string can be used.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p | |||
character(kind=CK, len=*), | intent(in) | :: | name |
Wrap json_value_create_object so that create_object
method may be called
with an actual argument corresponding to the dummy argument name
that is of
either ‘DEFAULT’ or ‘ISO_10646’ character kind.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p | |||
character(kind=CDK, len=*), | intent(in) | :: | name |
Allocate a json_value pointer and make it a real variable. The pointer should not already be allocated.
type(json_core) :: json
type(json_value),pointer :: p
call json%create_real(p,'value',1.0_RK)
Allocate a json_value pointer and make it a real(RK) variable. The pointer should not already be allocated.
type(json_value),pointer :: p
type(json_core) :: json
call json%create_real(p,'value',1.0_RK)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p | |||
real(kind=RK), | intent(in) | :: | val | |||
character(kind=CK, len=*), | intent(in) | :: | name |
A wrapper for json_value_create_real so that create_real
method
may be called with an actual argument corresponding to the dummy argument,
name
that may be of ‘DEFAULT’ or ‘ISO_10646’ character kind.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p | |||
real(kind=RK), | intent(in) | :: | val | |||
character(kind=CDK, len=*), | intent(in) | :: | name |
Alternate version of json_value_create_real where val=real32.
The value is converted into a real(RK)
variable internally.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p | |||
real(kind=real32), | intent(in) | :: | val | |||
character(kind=CK, len=*), | intent(in) | :: | name |
Alternate version of json_value_create_real32 where “name” is kind(CDK).
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p | |||
real(kind=real32), | intent(in) | :: | val | |||
character(kind=CDK, len=*), | intent(in) | :: | name |
Allocate a json_value pointer and make it a string variable. The pointer should not already be allocated.
type(json_core) :: json
type(json_value),pointer :: p
call json%create_string(p,'value','foobar')
Allocate a json_value pointer and make it a string variable. The pointer should not already be allocated.
type(json_value),pointer :: p
type(json_core) :: json
call json%create_string(p,'value','hello')
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p | |||
character(kind=CK, len=*), | intent(in) | :: | val | |||
character(kind=CK, len=*), | intent(in) | :: | name | |||
logical(kind=LK), | intent(in), | optional | :: | trim_str |
if TRIM() should be called for the |
|
logical(kind=LK), | intent(in), | optional | :: | adjustl_str |
if ADJUSTL() should be called for the |
Wrap json_value_create_string so that create_string
method may be called
with actual character string arguments for name
and val
that are BOTH of
‘DEFAULT’ or ‘ISO_10646’ character kind.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p | |||
character(kind=CDK, len=*), | intent(in) | :: | val | |||
character(kind=CDK, len=*), | intent(in) | :: | name | |||
logical(kind=LK), | intent(in), | optional | :: | trim_str |
if TRIM() should be called for the |
|
logical(kind=LK), | intent(in), | optional | :: | adjustl_str |
if ADJUSTL() should be called for the |
Parse the JSON string and populate the json_value tree.
Parse the JSON string and populate the json_value tree.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p |
output structure |
||
character(kind=CK, len=*), | intent(in) | :: | str |
string with JSON data |
Alternate version of json_parse_string, where str
is kind=CDK.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p |
output structure |
||
character(kind=CDK, len=*), | intent(in) | :: | str |
string with JSON data |
Destructor routine for a json_value pointer. This must be called explicitly if it is no longer needed, before it goes out of scope. Otherwise, a memory leak will result.
Destroy the json_value pointer before the variable goes out of scope:
subroutine example1()
type(json_core) :: json
type(json_value),pointer :: p
call json%create_object(p,'')
call json%add(p,'year',2015)
call json%print(p)
call json%destroy(p)
end subroutine example1
Note: it should NOT be called for a json_value pointer than has already been added to another json_value structure, since doing so may render the other structure invalid. Consider the following example:
subroutine example2(p)
type(json_core) :: json
type(json_value),pointer,intent(out) :: p
type(json_value),pointer :: q
call json%create_object(p,'')
call json%add(p,'year',2015)
call json%create_object(q,'q')
call json%add(q,'val',1)
call json%add(p, q) !add q to p structure
! do NOT call json%destroy(q) here, because q is
! now part of the output structure p. p should be destroyed
! somewhere upstream by the caller of this routine.
nullify(q) !OK, but not strictly necessary
end subroutine example2
Destroy a json_value linked-list structure.
The original FSON version of this routine was not properly freeing the memory. It was rewritten.
This routine destroys this variable, it’s children, and
(if destroy_next
is true) the subsequent elements in
an object or array. It does not destroy the parent or
previous elements.
There is some protection here to enable destruction of improperly-created linked lists. However, likely there are cases not handled. Use the json_value_validate method to validate a JSON structure that was manually created using json_value pointers.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p |
variable to destroy |
||
logical(kind=LK), | intent(in), | optional | :: | destroy_next |
if true, then |
Destructor for the json_core type.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(out) | :: | me |
Destructor for the json_core type.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(out) | :: | me |
check for error
Logical function to indicate if an exception has been thrown in a json_core.
type(json_core) :: json
type(json_value),pointer :: p
logical :: status_ok
character(len=:),allocatable :: error_msg
call json%load(filename='myfile.json',p)
if (json%failed()) then
call json%check_for_errors(status_ok, error_msg)
write(*,*) 'Error: '//error_msg
call json%clear_exceptions()
call json%destroy(p)
end if
Note that json_file contains a wrapper for this routine, which is used like:
type(json_file) :: f
logical :: status_ok
character(len=:),allocatable :: error_msg
call f%load(filename='myfile.json')
if (f%failed()) then
call f%check_for_errors(status_ok, error_msg)
write(*,*) 'Error: '//error_msg
call f%clear_exceptions()
call f%destroy()
end if
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(in) | :: | json |
will be true if an exception has been thrown.
Get data from a json_value linked list.
There are two versions (e.g. json_get_integer and json_get_integer_by_path). The first one gets the value from the json_value passed into the routine, while the second one gets the value from the json_value found by parsing the path. The path version is split up into unicode and non-unicode versions.
Returns the json_value pointer given the path string.
It uses one of three methods:
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | intent(in), | pointer | :: | me |
a JSON linked list |
|
character(kind=CK, len=*), | intent(in) | :: | path |
path to the variable |
||
type(json_value), | intent(out), | pointer | :: | p |
pointer to the variable
specified by |
|
logical(kind=LK), | intent(out), | optional | :: | found |
true if it was found |
Alternate version of json_get_by_path where “path” is kind=CDK.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | intent(in), | pointer | :: | me | ||
character(kind=CDK, len=*), | intent(in) | :: | path | |||
type(json_value), | intent(out), | pointer | :: | p | ||
logical(kind=LK), | intent(out), | optional | :: | found |
Get an integer value from a json_value.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | intent(in), | pointer | :: | me | ||
integer(kind=IK), | intent(out) | :: | value |
the integer value |
Get an integer value from a json_value, given the path string.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | intent(in), | pointer | :: | me | ||
character(kind=CK, len=*), | intent(in) | :: | path | |||
integer(kind=IK), | intent(out) | :: | value | |||
logical(kind=LK), | intent(out), | optional | :: | found | ||
integer(kind=IK), | intent(in), | optional | :: | default |
default value if not found |
Alternate version of json_get_integer_by_path, where “path” is kind=CDK.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | intent(in), | pointer | :: | me | ||
character(kind=CDK, len=*), | intent(in) | :: | path | |||
integer(kind=IK), | intent(out) | :: | value | |||
logical(kind=LK), | intent(out), | optional | :: | found | ||
integer(kind=IK), | intent(in), | optional | :: | default |
default value if not found |
Get an integer vector from a json_value.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | me | |||
integer(kind=IK), | intent(out), | dimension(:), allocatable | :: | vec |
Get an integer vector from a json_value, given the path string.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | intent(in), | pointer | :: | me | ||
character(kind=CK, len=*), | intent(in) | :: | path | |||
integer(kind=IK), | intent(out), | dimension(:), allocatable | :: | vec | ||
logical(kind=LK), | intent(out), | optional | :: | found | ||
integer(kind=IK), | intent(in), | optional, | dimension(:) | :: | default |
default value if not found |
Alternate version of json_get_integer_vec_by_path, where “path” is kind=CDK
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | me | |||
character(kind=CDK, len=*), | intent(in) | :: | path | |||
integer(kind=IK), | intent(out), | dimension(:), allocatable | :: | vec | ||
logical(kind=LK), | intent(out), | optional | :: | found | ||
integer(kind=IK), | intent(in), | optional, | dimension(:) | :: | default |
default value if not found |
Alternate version of json_get_real where value=real32.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | me | |||
real(kind=real32), | intent(out) | :: | value |
Alternate version of json_get_real_by_path where value=real32.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | me | |||
character(kind=CK, len=*), | intent(in) | :: | path | |||
real(kind=real32), | intent(out) | :: | value | |||
logical(kind=LK), | intent(out), | optional | :: | found | ||
real(kind=real32), | intent(in), | optional | :: | default |
default value if not found |
Alternate version of json_get_real32_by_path, where “path” is kind=CDK
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | me | |||
character(kind=CDK, len=*), | intent(in) | :: | path | |||
real(kind=real32), | intent(out) | :: | value | |||
logical(kind=LK), | intent(out), | optional | :: | found | ||
real(kind=real32), | intent(in), | optional | :: | default |
default value if not found |
Alternate version of json_get_real_vec where vec
is real32
.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | me | |||
real(kind=real32), | intent(out), | dimension(:), allocatable | :: | vec |
Alternate version of json_get_real_vec_by_path where vec
is real32
.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | intent(in), | pointer | :: | me | ||
character(kind=CK, len=*), | intent(in) | :: | path | |||
real(kind=real32), | intent(out), | dimension(:), allocatable | :: | vec | ||
logical(kind=LK), | intent(out), | optional | :: | found | ||
real(kind=real32), | intent(in), | optional, | dimension(:) | :: | default |
default value if not found |
Alternate version of json_get_real32_vec_by_path, where “path” is kind=CDK
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | me | |||
character(kind=CDK, len=*), | intent(in) | :: | path | |||
real(kind=real32), | intent(out), | dimension(:), allocatable | :: | vec | ||
logical(kind=LK), | intent(out), | optional | :: | found | ||
real(kind=real32), | intent(in), | optional, | dimension(:) | :: | default |
default value if not found |
Get a real value from a json_value.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | me | |||
real(kind=RK), | intent(out) | :: | value |
Get a real value from a json_value, given the path.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | me | |||
character(kind=CK, len=*), | intent(in) | :: | path | |||
real(kind=RK), | intent(out) | :: | value | |||
logical(kind=LK), | intent(out), | optional | :: | found | ||
real(kind=RK), | intent(in), | optional | :: | default |
default value if not found |
Alternate version of json_get_real_by_path, where “path” is kind=CDK
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | me | |||
character(kind=CDK, len=*), | intent(in) | :: | path | |||
real(kind=RK), | intent(out) | :: | value | |||
logical(kind=LK), | intent(out), | optional | :: | found | ||
real(kind=RK), | intent(in), | optional | :: | default |
default value if not found |
Get a real vector from a json_value.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | me | |||
real(kind=RK), | intent(out), | dimension(:), allocatable | :: | vec |
Get a real vector from a json_value, given the path.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | intent(in), | pointer | :: | me | ||
character(kind=CK, len=*), | intent(in) | :: | path | |||
real(kind=RK), | intent(out), | dimension(:), allocatable | :: | vec | ||
logical(kind=LK), | intent(out), | optional | :: | found | ||
real(kind=RK), | intent(in), | optional, | dimension(:) | :: | default |
default value if not found |
Alternate version of json_get_real_vec_by_path, where “path” is kind=CDK
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | me | |||
character(kind=CDK, len=*), | intent(in) | :: | path | |||
real(kind=RK), | intent(out), | dimension(:), allocatable | :: | vec | ||
logical(kind=LK), | intent(out), | optional | :: | found | ||
real(kind=RK), | intent(in), | optional, | dimension(:) | :: | default |
default value if not found |
Get a logical value from a json_value.
If strict_type_checking
is False, then the following assumptions are made:
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | intent(in), | pointer | :: | me | ||
logical(kind=LK), | intent(out) | :: | value |
Get a logical value from a json_value, given the path.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | intent(in), | pointer | :: | me | ||
character(kind=CK, len=*), | intent(in) | :: | path | |||
logical(kind=LK), | intent(out) | :: | value | |||
logical(kind=LK), | intent(out), | optional | :: | found | ||
logical(kind=LK), | intent(in), | optional | :: | default |
default value if not found |
Alternate version of json_get_logical_by_path, where “path” is kind=CDK
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | intent(in), | pointer | :: | me | ||
character(kind=CDK, len=*), | intent(in) | :: | path | |||
logical(kind=LK), | intent(out) | :: | value | |||
logical(kind=LK), | intent(out), | optional | :: | found | ||
logical(kind=LK), | intent(in), | optional | :: | default |
default value if not found |
Get a logical vector from json_value.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | intent(in), | pointer | :: | me | ||
logical(kind=LK), | intent(out), | dimension(:), allocatable | :: | vec |
Get a logical vector from a json_value, given the path.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | intent(in), | pointer | :: | me | ||
character(kind=CK, len=*), | intent(in) | :: | path | |||
logical(kind=LK), | intent(out), | dimension(:), allocatable | :: | vec | ||
logical(kind=LK), | intent(out), | optional | :: | found | ||
logical(kind=LK), | intent(in), | optional, | dimension(:) | :: | default |
Alternate version of json_get_logical_vec_by_path, where “path” is kind=CDK
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | intent(in), | pointer | :: | me | ||
character(kind=CDK, len=*), | intent(in) | :: | path | |||
logical(kind=LK), | intent(out), | dimension(:), allocatable | :: | vec | ||
logical(kind=LK), | intent(out), | optional | :: | found | ||
logical(kind=LK), | intent(in), | optional, | dimension(:) | :: | default |
Get a character string from a json_value.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | intent(in), | pointer | :: | me | ||
character(kind=CK, len=:), | intent(out), | allocatable | :: | value |
Get a character string from a json_value, given the path.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | intent(in), | pointer | :: | me | ||
character(kind=CK, len=*), | intent(in) | :: | path | |||
character(kind=CK, len=:), | intent(out), | allocatable | :: | value | ||
logical(kind=LK), | intent(out), | optional | :: | found | ||
character(kind=CK, len=*), | intent(in), | optional | :: | default |
Alternate version of json_get_string_by_path, where “path” is kind=CDK
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | intent(in), | pointer | :: | me | ||
character(kind=CDK, len=*), | intent(in) | :: | path | |||
character(kind=CK, len=:), | intent(out), | allocatable | :: | value | ||
logical(kind=LK), | intent(out), | optional | :: | found | ||
character(kind=CK, len=*), | intent(in), | optional | :: | default |
Get a string vector from a json_value.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | intent(in), | pointer | :: | me | ||
character(kind=CK, len=*), | intent(out), | dimension(:), allocatable | :: | vec |
Get a string vector from a json_value, given the path.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | intent(in), | pointer | :: | me | ||
character(kind=CK, len=*), | intent(in) | :: | path | |||
character(kind=CK, len=*), | intent(out), | dimension(:), allocatable | :: | vec | ||
logical(kind=LK), | intent(out), | optional | :: | found | ||
character(kind=CK, len=*), | intent(in), | optional, | dimension(:) | :: | default |
Alternate version of json_get_string_vec_by_path, where “path” is kind=CDK
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | intent(in), | pointer | :: | me | ||
character(kind=CDK, len=*), | intent(in) | :: | path | |||
character(kind=CK, len=*), | intent(out), | dimension(:), allocatable | :: | vec | ||
logical(kind=LK), | intent(out), | optional | :: | found | ||
character(kind=CK, len=*), | intent(in), | optional, | dimension(:) | :: | default |
Get a string vector from a json_value. This is an alternate version of json_get_string_vec. This one returns an allocatable length character (where the string length is the maximum length of any element in the array). It also returns an integer array of the actual sizes of the strings in the JSON structure.
This is somewhat inefficient since it does cycle through the array twice.
The allocation of vec
doesn’t work with
gfortran 4.9 or 5 due to compiler bugs
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | intent(in), | pointer | :: | me | ||
character(kind=CK, len=:), | intent(out), | dimension(:), allocatable | :: | vec | ||
integer(kind=IK), | intent(out), | dimension(:), allocatable | :: | ilen |
the actual length of each character string in the array |
Alternate version of json_get_alloc_string_vec where input is the path.
This is an alternate version of json_get_string_vec_by_path. This one returns an allocatable length character (where the string length is the maximum length of any element in the array). It also returns an integer array of the actual sizes of the strings in the JSON structure.
An alternative to using this routine is to use json_get_array with a callback function that gets the string from each element and populates a user-defined string type.
If the default
argument is used, and default_ilen
is not present,
then ilen
will just be returned as the length of the default
dummy
argument (all elements with the same length).
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | intent(in), | pointer | :: | me | ||
character(kind=CK, len=*), | intent(in) | :: | path | |||
character(kind=CK, len=:), | intent(out), | dimension(:), allocatable | :: | vec | ||
integer(kind=IK), | intent(out), | dimension(:), allocatable | :: | ilen |
the actual length of each character string in the array |
|
logical(kind=LK), | intent(out), | optional | :: | found | ||
character(kind=CK, len=*), | intent(in), | optional, | dimension(:) | :: | default | |
integer(kind=IK), | intent(in), | optional, | dimension(:) | :: | default_ilen |
the actual
length of |
Alternate version of json_get_alloc_string_vec_by_path, where “path” is kind=CDK
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | intent(in), | pointer | :: | me | ||
character(kind=CDK, len=*), | intent(in) | :: | path | |||
character(kind=CK, len=:), | intent(out), | dimension(:), allocatable | :: | vec | ||
integer(kind=IK), | intent(out), | dimension(:), allocatable | :: | ilen |
the actual length of each character string in the array |
|
logical(kind=LK), | intent(out), | optional | :: | found | ||
character(kind=CK, len=*), | intent(in), | optional, | dimension(:) | :: | default | |
integer(kind=IK), | intent(in), | optional, | dimension(:) | :: | default_ilen |
the actual
length of |
This routine calls the user-supplied json_array_callback_func subroutine for each element in the array.
For integer, real, logical, and character arrays,
higher-level routines are provided (see get
methods), so
this routine does not have to be used for those cases.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | intent(in), | pointer | :: | me | ||
procedure(json_array_callback_func) | :: | array_callback |
This routine calls the user-supplied array_callback subroutine for each element in the array (specified by the path).
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | intent(in), | pointer | :: | me | ||
character(kind=CK, len=*), | intent(in) | :: | path | |||
procedure(json_array_callback_func) | :: | array_callback | ||||
logical(kind=LK), | intent(out), | optional | :: | found |
Alternate version of json_get_array_by_path, where “path” is kind=CDK
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | intent(in), | pointer | :: | me | ||
character(kind=CDK, len=*), | intent(in) | :: | path | |||
procedure(json_array_callback_func) | :: | array_callback | ||||
logical(kind=LK), | intent(out), | optional | :: | found |
Return a child of a json_value structure.
Returns a child in the object or array given the index.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | intent(in), | pointer | :: | p |
object or array JSON data |
|
integer(kind=IK), | intent(in) | :: | idx |
index of the child (this is a 1-based Fortran style array index). |
||
type(json_value), | pointer | :: | child |
pointer to the child |
||
logical(kind=LK), | intent(out), | optional | :: | found |
true if the value was found (if not present, an exception will be thrown if it was not found. If present and not found, no exception will be thrown). |
Returns pointer to the first child of the object
(or null()
if it is not associated).
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | intent(in), | pointer | :: | p |
object or array JSON data |
|
type(json_value), | pointer | :: | child |
pointer to the child |
Returns a child in the object or array given the name string.
The name search can be case-sensitive or not, and can have significant trailing whitespace or not, depending on the settings in the json_core class.
The name
input is not a path, and is not parsed like it is in json_get_by_path.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | intent(in), | pointer | :: | p | ||
character(kind=CK, len=*), | intent(in) | :: | name |
the name of a child of |
||
type(json_value), | pointer | :: | child |
pointer to the child |
||
logical(kind=LK), | intent(out), | optional | :: | found |
true if the value was found (if not present, an exception will be thrown if it was not found. If present and not found, no exception will be thrown). |
Alternate version of json_value_get_child_by_name where name
is kind=CDK.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | intent(in), | pointer | :: | p | ||
character(kind=CDK, len=*), | intent(in) | :: | name | |||
type(json_value), | pointer | :: | child | |||
logical(kind=LK), | intent(out), | optional | :: | found |
Rewind the file to the beginning of the current line, and return this line. The file is assumed to be opened. This is the SEQUENTIAL version (see also get_current_line_from_file_stream).
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer(kind=IK), | intent(in) | :: | iunit |
file unit number |
||
character(kind=CK, len=:), | intent(out), | allocatable | :: | line |
current line |
Rewind the file to the beginning of the current line, and return this line. The file is assumed to be opened. This is the STREAM version (see also get_current_line_from_file_sequential).
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
integer(kind=IK), | intent(in) | :: | iunit |
file unit number |
||
character(kind=CK, len=:), | intent(out), | allocatable | :: | line |
current line |
get pointer to json_value next
Returns a pointer to the next of a json_value.
If there is no next, then a null()
pointer is returned.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | intent(in), | pointer | :: | p |
JSON object |
|
type(json_value), | intent(out), | pointer | :: | next |
pointer to |
get pointer to json_value parent
Returns a pointer to the parent of a json_value.
If there is no parent, then a null()
pointer is returned.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | intent(in), | pointer | :: | p |
JSON object |
|
type(json_value), | intent(out), | pointer | :: | parent |
pointer to |
get the path to a JSON variable in a structure:
Returns the path to a JSON object that is part of a linked list structure.
The path returned would be suitable for input to json_get_by_path and related routines.
If an error occurs (which in this case means a malformed
JSON structure) then an exception will be thrown, unless
found
is present, which will be set to false
. path
will be a blank string.
If json%path_mode/=1
, then the use_alt_array_tokens
and path_sep
inputs are ignored if present.
http://goessner.net/articles/JsonPath/ (path_mode=3
)
does not specify whether or not the keys should be escaped (this routine
assumes not, as does http://jsonpath.com).
Also, we are using Fortran-style 1-based array indices,
not 0-based, to agree with the assumption in path_mode=1
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | intent(in), | pointer | :: | p |
a JSON linked list object |
|
character(kind=CK, len=:), | intent(out), | allocatable | :: | path |
path to the variable |
|
logical(kind=LK), | intent(out), | optional | :: | found |
true if there were no problems |
|
logical(kind=LK), | intent(in), | optional | :: | use_alt_array_tokens |
if true, then ‘()’ are used for array elements
otherwise, ‘[]’ are used [default]
(only used if |
|
character(kind=CK, len=1), | intent(in), | optional | :: | path_sep |
character to use for path separator
(otherwise use |
Wrapper for json_get_path where “path” and “path_sep” are kind=CDK.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | intent(in), | pointer | :: | p |
a JSON linked list object |
|
character(kind=CDK, len=:), | intent(out), | allocatable | :: | path |
path to the variable |
|
logical(kind=LK), | intent(out), | optional | :: | found |
true if there were no problems |
|
logical(kind=LK), | intent(in), | optional | :: | use_alt_array_tokens |
if true, then ‘()’ are used for array elements otherwise, ‘[]’ are used [default] |
|
character(kind=CDK, len=1), | intent(in), | optional | :: | path_sep |
character to use for path separator (default is ‘.’) |
get pointer to json_value previous
Returns a pointer to the previous of a json_value.
If there is no previous, then a null()
pointer is returned.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | intent(in), | pointer | :: | p |
JSON object |
|
type(json_value), | intent(out), | pointer | :: | previous |
pointer to |
get pointer to json_value tail
Returns a pointer to the tail of a json_value
(the last child of an array of object).
If there is no tail, then a null()
pointer is returned.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | intent(in), | pointer | :: | p |
JSON object |
|
type(json_value), | intent(out), | pointer | :: | tail |
pointer to |
get info about a json_value
Returns information about a json_value.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p | |||
integer(kind=IK), | intent(out), | optional | :: | var_type |
variable type |
|
integer(kind=IK), | intent(out), | optional | :: | n_children |
number of children |
|
character(kind=CK, len=:), | intent(out), | optional, | allocatable | :: | name |
variable name |
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | intent(in), | pointer | :: | p |
a JSON linked list |
|
character(kind=CK, len=*), | intent(in) | :: | path |
path to the variable |
||
logical(kind=LK), | intent(out), | optional | :: | found |
true if it was found |
|
integer(kind=IK), | intent(out), | optional | :: | var_type |
variable type |
|
integer(kind=IK), | intent(out), | optional | :: | n_children |
number of children |
|
character(kind=CK, len=:), | intent(out), | optional, | allocatable | :: | name |
variable name |
Alternate version of json_info_by_path where “path” is kind=CDK.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | intent(in), | pointer | :: | p |
a JSON linked list |
|
character(kind=CDK, len=*), | intent(in) | :: | path |
path to the variable |
||
logical(kind=LK), | intent(out), | optional | :: | found |
true if it was found |
|
integer(kind=IK), | intent(out), | optional | :: | var_type |
variable type |
|
integer(kind=IK), | intent(out), | optional | :: | n_children |
number of children |
|
character(kind=CK, len=:), | intent(out), | optional, | allocatable | :: | name |
variable name |
to initialize some parsing parameters
Initialize the json_core instance.
The routine may be called before any of the json_core methods are used in order to specify certain parameters. If it is not called, then the defaults are used. This routine is also called internally by various routines. It can also be called to clear exceptions, or to reset some of the variables (note that only the arguments present are changed).
initialize_json_core, json_initialize, initialize_json_core_in_file, and initialize_json_file all have a similar interface.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | me | |||
logical(kind=LK), | intent(in), | optional | :: | verbose |
mainly useful for debugging (default is false) |
|
logical(kind=LK), | intent(in), | optional | :: | compact_reals |
to compact the real number strings for output (default is true) |
|
logical(kind=LK), | intent(in), | optional | :: | print_signs |
always print numeric sign (default is false) |
|
character(kind=CDK, len=*), | intent(in), | optional | :: | real_format |
Real number format: ‘E’ [default], ‘*’, ‘G’, ‘EN’, or ‘ES’ |
|
integer(kind=IK), | intent(in), | optional | :: | spaces_per_tab |
number of spaces per tab for indenting (default is 2) |
|
logical(kind=LK), | intent(in), | optional | :: | strict_type_checking |
if true, no integer, double, or logical type
conversions are done for the |
|
logical(kind=LK), | intent(in), | optional | :: | trailing_spaces_significant |
for name and path comparisons, is trailing space to be considered significant. (default is false) |
|
logical(kind=LK), | intent(in), | optional | :: | case_sensitive_keys |
for name and path comparisons, are they case sensitive. (default is true) |
|
logical(kind=LK), | intent(in), | optional | :: | no_whitespace |
if true, printing the JSON structure is done without adding any non-significant spaces or linebreaks (default is false) |
|
logical(kind=LK), | intent(in), | optional | :: | unescape_strings |
If false, then the raw escaped string is returned from json_get_string and similar routines. If true [default], then the string is returned unescaped. |
|
character(kind=CK, len=*), | intent(in), | optional | :: | comment_char |
If present, these characters are used
to denote comments in the JSON file,
which will be ignored if present.
Example: |
|
integer(kind=IK), | intent(in), | optional | :: | path_mode |
How the path strings are interpreted in the
|
|
character(kind=CK, len=1), | intent(in), | optional | :: | path_separator |
The |
|
logical(kind=LK), | intent(in), | optional | :: | compress_vectors |
If true, then arrays of integers,
nulls, doubles, and logicals are
printed all on one line.
[Note: |
|
logical(kind=LK), | intent(in), | optional | :: | allow_duplicate_keys |
|
|
logical(kind=LK), | intent(in), | optional | :: | escape_solidus |
Note that this option does not affect parsing (both escaped and unescaped are still valid in all cases). |
|
logical(kind=LK), | intent(in), | optional | :: | stop_on_error |
If an exception is raised, then immediately quit. (Default is False). |
|
integer(kind=IK), | intent(in), | optional | :: | null_to_real_mode |
if |
|
integer(kind=IK), | intent(in), | optional | :: | non_normal_mode |
How to serialize NaN, Infinity, and -Infinity real values: |
|
logical(kind=LK), | intent(in), | optional | :: | use_quiet_nan |
|
|
logical(kind=LK), | intent(in), | optional | :: | strict_integer_type_checking |
(default is true) |
insert a new element after an existing one, updating the JSON structure accordingly
Inserts element
after p
, and updates the JSON structure accordingly.
program test
use json_module
implicit none
logical(json_LK) :: found
type(json_core) :: json
type(json_value),pointer :: p,new,element
call json%load(file='myfile.json', p=p)
call json%get(p,'x(3)',element,found) ! get pointer to an array element in the file
call json%create_integer(new,1,'') ! create a new element
call json%insert_after(element,new) ! insert new element after x(3)
call json%print(p,'myfile2.json') ! write it to a file
call json%destroy(p) ! cleanup
end program test
element
are carried along. p
[1] - [2] - [3] - [4]
|
[5] - [6] - [7] n=3 elements inserted
element last
Result is:
[1] - [2] - [5] - [6] - [7] - [3] - [4]
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p |
a value from a JSON structure (presumably, this is a child of an object or array). |
||
type(json_value), | pointer | :: | element |
the element to insert after |
Inserts element
after the idx
-th child of p
,
and updates the JSON structure accordingly. This is just
a wrapper for json_value_insert_after.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p |
a JSON object or array. |
||
integer(kind=IK), | intent(in) | :: | idx |
the index of the child of |
||
type(json_value), | pointer | :: | element |
the element to insert |
Check if a json_value is a descendant of another.
Returns True if p2
is a descendant of p1
(i.e, a child, or a child of child, etc.)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p1 | |||
type(json_value), | pointer | :: | p2 |
Returns true if all the children are the same type (and a scalar).
Note that integers and reals are considered the same type for this purpose.
This routine is used for the compress_vectors
option.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p |
if all elements of a vector are scalars of the same type
Add an integer value to a json_value, given the path.
If the path points to an existing variable in the structure, then this routine will destroy it and replace it with the new value.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | me |
the JSON structure |
||
character(kind=CK, len=*), | intent(in) | :: | path |
the path to the variable |
||
integer(kind=IK), | intent(in) | :: | value |
the value to add |
||
logical(kind=LK), | intent(out), | optional | :: | found |
if the variable was found |
|
logical(kind=LK), | intent(out), | optional | :: | was_created |
if the variable had to be created |
Wrapper to json_add_integer_by_path for adding an integer vector by path.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | me |
the JSON structure |
||
character(kind=CK, len=*), | intent(in) | :: | path |
the path to the variable |
||
integer(kind=IK), | intent(in), | dimension(:) | :: | value |
the vector to add |
|
logical(kind=LK), | intent(out), | optional | :: | found |
if the variable was found |
|
logical(kind=LK), | intent(out), | optional | :: | was_created |
if the variable had to be created |
Add a logical value to a json_value, given the path.
If the path points to an existing variable in the structure, then this routine will destroy it and replace it with the new value.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | me |
the JSON structure |
||
character(kind=CK, len=*), | intent(in) | :: | path |
the path to the variable |
||
logical(kind=LK), | intent(in) | :: | value |
the value to add |
||
logical(kind=LK), | intent(out), | optional | :: | found |
if the variable was found |
|
logical(kind=LK), | intent(out), | optional | :: | was_created |
if the variable had to be created |
Wrapper to json_add_logical_by_path for adding a logical vector by path.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | me |
the JSON structure |
||
character(kind=CK, len=*), | intent(in) | :: | path |
the path to the variable |
||
logical(kind=LK), | intent(in), | dimension(:) | :: | value |
the vector to add |
|
logical(kind=LK), | intent(out), | optional | :: | found |
if the variable was found |
|
logical(kind=LK), | intent(out), | optional | :: | was_created |
if the variable had to be created |
Add a new member (json_value
pointer) to a JSON structure, given the path.
If the path points to an existing variable in the structure, then this routine will destroy it and replace it with the new value.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | me |
the JSON structure |
||
character(kind=CK, len=*), | intent(in) | :: | path |
the path to the variable |
||
type(json_value), | intent(in), | pointer | :: | p |
the value to add |
|
logical(kind=LK), | intent(out), | optional | :: | found |
if the variable was found |
|
logical(kind=LK), | intent(out), | optional | :: | was_created |
if the variable had to be created |
Alternate version of json_add_real_by_path where value=real32.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | me |
the JSON structure |
||
character(kind=CK, len=*), | intent(in) | :: | path |
the path to the variable |
||
real(kind=real32), | intent(in) | :: | value |
the value to add |
||
logical(kind=LK), | intent(out), | optional | :: | found |
if the variable was found |
|
logical(kind=LK), | intent(out), | optional | :: | was_created |
if the variable had to be created |
Wrapper to json_add_real_by_path for adding a real vector by path.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | me |
the JSON structure |
||
character(kind=CK, len=*), | intent(in) | :: | path |
the path to the variable |
||
real(kind=real32), | intent(in), | dimension(:) | :: | value |
the vector to add |
|
logical(kind=LK), | intent(out), | optional | :: | found |
if the variable was found |
|
logical(kind=LK), | intent(out), | optional | :: | was_created |
if the variable had to be created |
Add an real value to a json_value, given the path.
If the path points to an existing variable in the structure, then this routine will destroy it and replace it with the new value.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | me |
the JSON structure |
||
character(kind=CK, len=*), | intent(in) | :: | path |
the path to the variable |
||
real(kind=RK), | intent(in) | :: | value |
the value to add |
||
logical(kind=LK), | intent(out), | optional | :: | found |
if the variable was found |
|
logical(kind=LK), | intent(out), | optional | :: | was_created |
if the variable had to be created |
Wrapper to json_add_real_by_path for adding a real vector by path.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | me |
the JSON structure |
||
character(kind=CK, len=*), | intent(in) | :: | path |
the path to the variable |
||
real(kind=RK), | intent(in), | dimension(:) | :: | value |
the vector to add |
|
logical(kind=LK), | intent(out), | optional | :: | found |
if the variable was found |
|
logical(kind=LK), | intent(out), | optional | :: | was_created |
if the variable had to be created |
Add a string value to a json_value, given the path.
If the path points to an existing variable in the structure, then this routine will destroy it and replace it with the new value.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | me |
the JSON structure |
||
character(kind=CK, len=*), | intent(in) | :: | path |
the path to the variable |
||
character(kind=CK, len=*), | intent(in) | :: | value |
the value to add |
||
logical(kind=LK), | intent(out), | optional | :: | found |
if the variable was found |
|
logical(kind=LK), | intent(out), | optional | :: | was_created |
if the variable had to be created |
|
logical(kind=LK), | intent(in), | optional | :: | trim_str |
if TRIM() should be called for each element |
|
logical(kind=LK), | intent(in), | optional | :: | adjustl_str |
if ADJUSTL() should be called for each element |
Wrapper for json_add_string_by_path where “path” is kind=CDK.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | me |
the JSON structure |
||
character(kind=CDK, len=*), | intent(in) | :: | path |
the path to the variable |
||
character(kind=CK, len=*), | intent(in) | :: | value |
the value to add |
||
logical(kind=LK), | intent(out), | optional | :: | found |
if the variable was found |
|
logical(kind=LK), | intent(out), | optional | :: | was_created |
if the variable had to be created |
|
logical(kind=LK), | intent(in), | optional | :: | trim_str |
if TRIM() should be called for each element |
|
logical(kind=LK), | intent(in), | optional | :: | adjustl_str |
if ADJUSTL() should be called for each element |
Wrapper for json_add_string_by_path where “value” is kind=CDK.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | me |
the JSON structure |
||
character(kind=CK, len=*), | intent(in) | :: | path |
the path to the variable |
||
character(kind=CDK, len=*), | intent(in) | :: | value |
the value to add |
||
logical(kind=LK), | intent(out), | optional | :: | found |
if the variable was found |
|
logical(kind=LK), | intent(out), | optional | :: | was_created |
if the variable had to be created |
|
logical(kind=LK), | intent(in), | optional | :: | trim_str |
if TRIM() should be called for each element |
|
logical(kind=LK), | intent(in), | optional | :: | adjustl_str |
if ADJUSTL() should be called for each element |
Wrapper to json_add_string_by_path for adding a string vector by path.
The ilen
input can be used to specify the actual lengths of the
the strings in the array. They must all be <= len(value)
.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | me |
the JSON structure |
||
character(kind=CK, len=*), | intent(in) | :: | path |
the path to the variable |
||
character(kind=CK, len=*), | intent(in), | dimension(:) | :: | value |
the vector to add |
|
logical(kind=LK), | intent(out), | optional | :: | found |
if the variable was found |
|
logical(kind=LK), | intent(out), | optional | :: | was_created |
if the variable had to be created |
|
integer(kind=IK), | intent(in), | optional, | dimension(:) | :: | ilen |
the string lengths of each
element in |
logical(kind=LK), | intent(in), | optional | :: | trim_str |
if TRIM() should be called for each element |
|
logical(kind=LK), | intent(in), | optional | :: | adjustl_str |
if ADJUSTL() should be called for each element |
Wrapper for json_add_string_vec_by_path where “path” is kind=CDK).
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | me |
the JSON structure |
||
character(kind=CDK, len=*), | intent(in) | :: | path |
the path to the variable |
||
character(kind=CK, len=*), | intent(in), | dimension(:) | :: | value |
the vector to add |
|
logical(kind=LK), | intent(out), | optional | :: | found |
if the variable was found |
|
logical(kind=LK), | intent(out), | optional | :: | was_created |
if the variable had to be created |
|
integer(kind=IK), | intent(in), | optional, | dimension(:) | :: | ilen |
the string lengths of each
element in |
logical(kind=LK), | intent(in), | optional | :: | trim_str |
if TRIM() should be called for each element |
|
logical(kind=LK), | intent(in), | optional | :: | adjustl_str |
if ADJUSTL() should be called for each element |
Wrapper for json_add_string_vec_by_path where “value” is kind=CDK).
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | me |
the JSON structure |
||
character(kind=CK, len=*), | intent(in) | :: | path |
the path to the variable |
||
character(kind=CDK, len=*), | intent(in), | dimension(:) | :: | value |
the vector to add |
|
logical(kind=LK), | intent(out), | optional | :: | found |
if the variable was found |
|
logical(kind=LK), | intent(out), | optional | :: | was_created |
if the variable had to be created |
|
integer(kind=IK), | intent(in), | optional, | dimension(:) | :: | ilen |
the string lengths of each
element in |
logical(kind=LK), | intent(in), | optional | :: | trim_str |
if TRIM() should be called for each element |
|
logical(kind=LK), | intent(in), | optional | :: | adjustl_str |
if ADJUSTL() should be called for each element |
Returns the json_value pointer given the path string, If necessary, by creating the variables as needed.
By default, the leaf node and any empty array elements
are created as json_null
values.
It only works for path_mode=1
or path_mode=3
.
An error will be thrown for path_mode=2
(RFC 6901).
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | intent(in), | pointer | :: | me |
a JSON linked list |
|
character(kind=CK, len=*), | intent(in) | :: | path |
path to the variable |
||
type(json_value), | intent(out), | optional, | pointer | :: | p |
pointer to the variable
specify by |
logical(kind=LK), | intent(out), | optional | :: | found |
true if there were no errors (variable found or created) |
|
logical(kind=LK), | intent(out), | optional | :: | was_created |
true if it was actually created (as opposed to already being there) |
Get a string vector from a json_value. This is an alternate version of json_get_string_vec. This one returns an allocatable length character (where the string length is the maximum length of any element in the array). It also returns an integer array of the actual sizes of the strings in the JSON structure.
This is somewhat inefficient since it does cycle through the array twice.
The allocation of vec
doesn’t work with
gfortran 4.9 or 5 due to compiler bugs
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | intent(in), | pointer | :: | me | ||
character(kind=CK, len=:), | intent(out), | dimension(:), allocatable | :: | vec | ||
integer(kind=IK), | intent(out), | dimension(:), allocatable | :: | ilen |
the actual length of each character string in the array |
Alternate version of json_get_alloc_string_vec where input is the path.
This is an alternate version of json_get_string_vec_by_path. This one returns an allocatable length character (where the string length is the maximum length of any element in the array). It also returns an integer array of the actual sizes of the strings in the JSON structure.
An alternative to using this routine is to use json_get_array with a callback function that gets the string from each element and populates a user-defined string type.
If the default
argument is used, and default_ilen
is not present,
then ilen
will just be returned as the length of the default
dummy
argument (all elements with the same length).
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | intent(in), | pointer | :: | me | ||
character(kind=CK, len=*), | intent(in) | :: | path | |||
character(kind=CK, len=:), | intent(out), | dimension(:), allocatable | :: | vec | ||
integer(kind=IK), | intent(out), | dimension(:), allocatable | :: | ilen |
the actual length of each character string in the array |
|
logical(kind=LK), | intent(out), | optional | :: | found | ||
character(kind=CK, len=*), | intent(in), | optional, | dimension(:) | :: | default | |
integer(kind=IK), | intent(in), | optional, | dimension(:) | :: | default_ilen |
the actual
length of |
This routine calls the user-supplied json_array_callback_func subroutine for each element in the array.
For integer, real, logical, and character arrays,
higher-level routines are provided (see get
methods), so
this routine does not have to be used for those cases.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | intent(in), | pointer | :: | me | ||
procedure(json_array_callback_func) | :: | array_callback |
This routine calls the user-supplied array_callback subroutine for each element in the array (specified by the path).
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | intent(in), | pointer | :: | me | ||
character(kind=CK, len=*), | intent(in) | :: | path | |||
procedure(json_array_callback_func) | :: | array_callback | ||||
logical(kind=LK), | intent(out), | optional | :: | found |
Returns the json_value pointer given the path string.
It uses one of three methods:
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | intent(in), | pointer | :: | me |
a JSON linked list |
|
character(kind=CK, len=*), | intent(in) | :: | path |
path to the variable |
||
type(json_value), | intent(out), | pointer | :: | p |
pointer to the variable
specified by |
|
logical(kind=LK), | intent(out), | optional | :: | found |
true if it was found |
Returns the json_value pointer given the path string.
type(json_core) :: json
type(json_value),pointer :: dat,p
logical :: found
!...
call json%initialize(path_mode=1) ! this is the default so not strictly necessary.
call json%get(dat,'data(2).version',p,found)
The syntax used here is a subset of the http://goessner.net/articles/JsonPath/ “dot–notation”. The following special characters are used to denote paths:
$
- root@
- this.
- child object member (note this can be changed using json%path_separator
)[]
or ()
- child array element (note that indices are 1-based)Thus, if any of these characters are present in the name key,
this routine cannot be used to get the value.
In that case, the get_child
methods would need to be used.
Or, the alternate json_get_by_path_rfc6901 could be used.
The syntax is inherited from FSON, and is basically a subset of JSONPath “dot-notation”, with the additional allowance of () for array elements.
JSON null
values are used here for unknown variables when create_it
is True.
So, it is possible that an existing null variable can be converted to another
type (object or array) if a child is specified in the path. Doing it this way
to avoid having to use another type (say json_unknown
) that would have to be
converted to null once all the variables have been created (user would have
had to do this).
See (**) in code. I think we need to protect for memory leaks when changing the type of a variable that already exists.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | intent(in), | pointer | :: | me |
a JSON linked list |
|
character(kind=CK, len=*), | intent(in) | :: | path |
path to the variable |
||
type(json_value), | intent(out), | pointer | :: | p |
pointer to the variable
specify by |
|
logical(kind=LK), | intent(out), | optional | :: | found |
true if it was found |
|
logical(kind=LK), | intent(in), | optional | :: | create_it |
if a variable is not present
in the path, then it is created.
the leaf node is returned as
a |
|
logical(kind=LK), | intent(out), | optional | :: | was_created |
if |
Returns the json_value pointer given the path string, using the “JSON Pointer” path specification defined by the JSONPath “bracket-notation”.
The first character $
is optional, and signifies the root
of the structure. If it is not present, then the first key
is taken to be in the me
object.
Single or real quotes may be used.
type(json_core) :: json
type(json_value),pointer :: dat,p
logical :: found
!...
call json%initialize(path_mode=3)
call json%get(dat,"$['store']['book'][1]['title']",p,found)
Uses 1-based array indices (same as json_get_by_path_default, but unlike json_get_by_path_rfc6901 which uses 0-based indices).
When create_it=True
, if the variable already exists and is a type
that is not compatible with the usage in the path
, then it is
destroyed and replaced with what is specified in the path
. Note that
this applies the all variables in the path as it is created. Currently,
this behavior is different from json_get_by_path_default.
JSON null
values are used here for unknown variables
when create_it
is True.
Note that if using single quotes, this routine cannot parse
a key containing ']
. If using real quotes, this routine
cannot parse a key containing "]
. If the key contains both
']
and "]
, there is no way to parse it using this routine.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | intent(in), | pointer | :: | me |
a JSON linked list |
|
character(kind=CK, len=*), | intent(in) | :: | path |
path to the variable (using JSONPath “bracket-notation”) |
||
type(json_value), | intent(out), | pointer | :: | p |
pointer to the variable
specify by |
|
logical(kind=LK), | intent(out), | optional | :: | found |
true if it was found |
|
logical(kind=LK), | intent(in), | optional | :: | create_it |
if a variable is not present
in the path, then it is created.
the leaf node is returned as
a |
|
logical(kind=LK), | intent(out), | optional | :: | was_created |
if |
Returns the json_value pointer given the path string, using the “JSON Pointer” path specification defined by RFC 6901.
Note that trailing whitespace significance and case sensitivity
are user-specified. To fully conform to the RFC 6901 standard,
should probably set (via initialize
):
case_sensitive_keys = .true.
[this is the default setting]trailing_spaces_significant = .true.
[this is not the default setting]allow_duplicate_keys = .false.
[this is not the default setting] type(json_core) :: json
type(json_value),pointer :: dat,p
logical :: found
!...
call json%initialize(path_mode=2)
call json%get(dat,'/data/2/version',p,found)
Not doing anything special about the -
character to index an array.
This is considered a normal error.
Unlike in the default path mode, the array indices here are 0-based (in accordance with the RFC 6901 standard)
Not checking if the member that is referenced is unique. (according to the standard, evaluation of non-unique references should fail). Like json_get_by_path_default, this one will just return the first instance it encounters. This might be changed in the future.
I think the standard indicates that the input paths should use escaped JSON strings (currently we are assuming they are not escaped).
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | intent(in), | pointer | :: | me |
a JSON linked list |
|
character(kind=CK, len=*), | intent(in) | :: | path |
path to the variable (an RFC 6901 “JSON Pointer”) |
||
type(json_value), | intent(out), | pointer | :: | p |
pointer to the variable
specify by |
|
logical(kind=LK), | intent(out), | optional | :: | found |
true if it was found |
Get an integer value from a json_value.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | intent(in), | pointer | :: | me | ||
integer(kind=IK), | intent(out) | :: | value |
the integer value |
Get an integer value from a json_value, given the path string.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | intent(in), | pointer | :: | me | ||
character(kind=CK, len=*), | intent(in) | :: | path | |||
integer(kind=IK), | intent(out) | :: | value | |||
logical(kind=LK), | intent(out), | optional | :: | found | ||
integer(kind=IK), | intent(in), | optional | :: | default |
default value if not found |
Get an integer vector from a json_value.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | me | |||
integer(kind=IK), | intent(out), | dimension(:), allocatable | :: | vec |
Get an integer vector from a json_value, given the path string.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | intent(in), | pointer | :: | me | ||
character(kind=CK, len=*), | intent(in) | :: | path | |||
integer(kind=IK), | intent(out), | dimension(:), allocatable | :: | vec | ||
logical(kind=LK), | intent(out), | optional | :: | found | ||
integer(kind=IK), | intent(in), | optional, | dimension(:) | :: | default |
default value if not found |
Get a logical value from a json_value.
If strict_type_checking
is False, then the following assumptions are made:
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | intent(in), | pointer | :: | me | ||
logical(kind=LK), | intent(out) | :: | value |
Get a logical value from a json_value, given the path.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | intent(in), | pointer | :: | me | ||
character(kind=CK, len=*), | intent(in) | :: | path | |||
logical(kind=LK), | intent(out) | :: | value | |||
logical(kind=LK), | intent(out), | optional | :: | found | ||
logical(kind=LK), | intent(in), | optional | :: | default |
default value if not found |
Get a logical vector from json_value.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | intent(in), | pointer | :: | me | ||
logical(kind=LK), | intent(out), | dimension(:), allocatable | :: | vec |
Get a logical vector from a json_value, given the path.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | intent(in), | pointer | :: | me | ||
character(kind=CK, len=*), | intent(in) | :: | path | |||
logical(kind=LK), | intent(out), | dimension(:), allocatable | :: | vec | ||
logical(kind=LK), | intent(out), | optional | :: | found | ||
logical(kind=LK), | intent(in), | optional, | dimension(:) | :: | default |
Returns the path to a JSON object that is part of a linked list structure.
The path returned would be suitable for input to json_get_by_path and related routines.
If an error occurs (which in this case means a malformed
JSON structure) then an exception will be thrown, unless
found
is present, which will be set to false
. path
will be a blank string.
If json%path_mode/=1
, then the use_alt_array_tokens
and path_sep
inputs are ignored if present.
http://goessner.net/articles/JsonPath/ (path_mode=3
)
does not specify whether or not the keys should be escaped (this routine
assumes not, as does http://jsonpath.com).
Also, we are using Fortran-style 1-based array indices,
not 0-based, to agree with the assumption in path_mode=1
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | intent(in), | pointer | :: | p |
a JSON linked list object |
|
character(kind=CK, len=:), | intent(out), | allocatable | :: | path |
path to the variable |
|
logical(kind=LK), | intent(out), | optional | :: | found |
true if there were no problems |
|
logical(kind=LK), | intent(in), | optional | :: | use_alt_array_tokens |
if true, then ‘()’ are used for array elements
otherwise, ‘[]’ are used [default]
(only used if |
|
character(kind=CK, len=1), | intent(in), | optional | :: | path_sep |
character to use for path separator
(otherwise use |
Get a real value from a json_value.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | me | |||
real(kind=RK), | intent(out) | :: | value |
Alternate version of json_get_real where value=real32.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | me | |||
real(kind=real32), | intent(out) | :: | value |
Alternate version of json_get_real_by_path where value=real32.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | me | |||
character(kind=CK, len=*), | intent(in) | :: | path | |||
real(kind=real32), | intent(out) | :: | value | |||
logical(kind=LK), | intent(out), | optional | :: | found | ||
real(kind=real32), | intent(in), | optional | :: | default |
default value if not found |
Alternate version of json_get_real_vec where vec
is real32
.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | me | |||
real(kind=real32), | intent(out), | dimension(:), allocatable | :: | vec |
Alternate version of json_get_real_vec_by_path where vec
is real32
.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | intent(in), | pointer | :: | me | ||
character(kind=CK, len=*), | intent(in) | :: | path | |||
real(kind=real32), | intent(out), | dimension(:), allocatable | :: | vec | ||
logical(kind=LK), | intent(out), | optional | :: | found | ||
real(kind=real32), | intent(in), | optional, | dimension(:) | :: | default |
default value if not found |
Get a real value from a json_value, given the path.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | me | |||
character(kind=CK, len=*), | intent(in) | :: | path | |||
real(kind=RK), | intent(out) | :: | value | |||
logical(kind=LK), | intent(out), | optional | :: | found | ||
real(kind=RK), | intent(in), | optional | :: | default |
default value if not found |
Get a real vector from a json_value.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | me | |||
real(kind=RK), | intent(out), | dimension(:), allocatable | :: | vec |
Get a real vector from a json_value, given the path.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | intent(in), | pointer | :: | me | ||
character(kind=CK, len=*), | intent(in) | :: | path | |||
real(kind=RK), | intent(out), | dimension(:), allocatable | :: | vec | ||
logical(kind=LK), | intent(out), | optional | :: | found | ||
real(kind=RK), | intent(in), | optional, | dimension(:) | :: | default |
default value if not found |
Get a character string from a json_value.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | intent(in), | pointer | :: | me | ||
character(kind=CK, len=:), | intent(out), | allocatable | :: | value |
Get a character string from a json_value, given the path.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | intent(in), | pointer | :: | me | ||
character(kind=CK, len=*), | intent(in) | :: | path | |||
character(kind=CK, len=:), | intent(out), | allocatable | :: | value | ||
logical(kind=LK), | intent(out), | optional | :: | found | ||
character(kind=CK, len=*), | intent(in), | optional | :: | default |
Get a string vector from a json_value.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | intent(in), | pointer | :: | me | ||
character(kind=CK, len=*), | intent(out), | dimension(:), allocatable | :: | vec |
Get a string vector from a json_value, given the path.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | intent(in), | pointer | :: | me | ||
character(kind=CK, len=*), | intent(in) | :: | path | |||
character(kind=CK, len=*), | intent(out), | dimension(:), allocatable | :: | vec | ||
logical(kind=LK), | intent(out), | optional | :: | found | ||
character(kind=CK, len=*), | intent(in), | optional, | dimension(:) | :: | default |
Returns information about a json_value.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p | |||
integer(kind=IK), | intent(out), | optional | :: | var_type |
variable type |
|
integer(kind=IK), | intent(out), | optional | :: | n_children |
number of children |
|
character(kind=CK, len=:), | intent(out), | optional, | allocatable | :: | name |
variable name |
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | intent(in), | pointer | :: | p |
a JSON linked list |
|
character(kind=CK, len=*), | intent(in) | :: | path |
path to the variable |
||
logical(kind=LK), | intent(out), | optional | :: | found |
true if it was found |
|
integer(kind=IK), | intent(out), | optional | :: | var_type |
variable type |
|
integer(kind=IK), | intent(out), | optional | :: | n_children |
number of children |
|
character(kind=CK, len=:), | intent(out), | optional, | allocatable | :: | name |
variable name |
Alternate version of json_info that returns matrix information about a json_value.
A json_value is a valid rank 2 matrix if all of the following are true:
The idea here is that if it is a valid matrix, it can be interoperable with a Fortran rank 2 array of the same type.
The following example is an array with var_type=json_integer
,
n_sets=3
, and set_size=4
{
"matrix": [
[1,2,3,4],
[5,6,7,8],
[9,10,11,12]
]
}
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p |
a JSON linked list |
||
logical(kind=LK), | intent(out) | :: | is_matrix |
true if it is a valid matrix |
||
integer(kind=IK), | intent(out), | optional | :: | var_type |
variable type of data in the matrix (if all elements have the same type) |
|
integer(kind=IK), | intent(out), | optional | :: | n_sets |
number of data sets (i.e., matrix rows if using row-major order) |
|
integer(kind=IK), | intent(out), | optional | :: | set_size |
size of each data set (i.e., matrix cols if using row-major order) |
|
character(kind=CK, len=:), | intent(out), | optional, | allocatable | :: | name |
variable name |
Returns matrix information about a json_value, given the path.
If found
is present, no exceptions will be thrown if an
error occurs. Otherwise, an exception will be thrown if the
variable is not found.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p |
a JSON linked list |
||
character(kind=CK, len=*), | intent(in) | :: | path |
path to the variable |
||
logical(kind=LK), | intent(out) | :: | is_matrix |
true if it is a valid matrix |
||
logical(kind=LK), | intent(out), | optional | :: | found |
true if it was found |
|
integer(kind=IK), | intent(out), | optional | :: | var_type |
variable type of data in the matrix (if all elements have the same type) |
|
integer(kind=IK), | intent(out), | optional | :: | n_sets |
number of data sets (i.e., matrix rows if using row-major order) |
|
integer(kind=IK), | intent(out), | optional | :: | set_size |
size of each data set (i.e., matrix cols if using row-major order) |
|
character(kind=CK, len=:), | intent(out), | optional, | allocatable | :: | name |
variable name |
Parse the JSON file and populate the json_value tree.
The inputs can be:
file
& unit
: the specified unit is used to read JSON from file.
[note if unit is already open, then the filename is ignored]file
: JSON is read from file using internal unit number type(json_core) :: json
type(json_value),pointer :: p
call json%load(file='myfile.json', p=p)
When calling this routine, any exceptions thrown from previous calls will automatically be cleared.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
character(kind=CDK, len=*), | intent(in) | :: | file |
JSON file name |
||
type(json_value), | pointer | :: | p |
output structure |
||
integer(kind=IK), | intent(in), | optional | :: | unit |
file unit number (/= 0) |
Parse the JSON string and populate the json_value tree.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p |
output structure |
||
character(kind=CK, len=*), | intent(in) | :: | str |
string with JSON data |
Print the json_value structure to the console (output_unit
).
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | intent(in), | pointer | :: | p |
Print the json_value structure to a file.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | intent(in), | pointer | :: | p | ||
character(kind=CDK, len=*), | intent(in) | :: | filename |
the filename to print to (should not already be open) |
Print the json_value structure to a file.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | intent(in), | pointer | :: | p | ||
integer(kind=IK), | intent(in) | :: | iunit |
the file unit (the file must already have been opened, can’t be -1). |
Rename a json_value, given the path.
this is a wrapper for json_value_rename.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | intent(in), | pointer | :: | me | ||
character(kind=CK, len=*), | intent(in) | :: | path |
path to the variable to rename |
||
character(kind=CK, len=*), | intent(in) | :: | name |
the new name |
||
logical(kind=LK), | intent(out), | optional | :: | found |
if there were no errors |
Alternate version of json_rename_by_path, where “name” is kind=CDK
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | intent(in), | pointer | :: | me | ||
character(kind=CK, len=*), | intent(in) | :: | path | |||
character(kind=CDK, len=*), | intent(in) | :: | name | |||
logical(kind=LK), | intent(out), | optional | :: | found |
Alternate version of json_rename_by_path, where “path” is kind=CDK
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | intent(in), | pointer | :: | me | ||
character(kind=CDK, len=*), | intent(in) | :: | path | |||
character(kind=CK, len=*), | intent(in) | :: | name | |||
logical(kind=LK), | intent(out), | optional | :: | found |
Returns information about character strings returned from a json_value.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p | |||
integer(kind=IK), | intent(out), | optional, | dimension(:), allocatable | :: | ilen |
if |
integer(kind=IK), | intent(out), | optional | :: | max_str_len |
The maximum length required to
hold the string representation returned
by a call to a |
|
logical(kind=LK), | intent(out), | optional | :: | found |
true if there were no errors. if not present, an error will throw an exception |
Throw an exception in the json_core. This routine sets the error flag, and prevents any subsequent routine from doing anything, until json_clear_exceptions is called.
If is_verbose
is true, this will also print a
traceback if the Intel compiler is used.
If stop_on_error
is true, then the program is stopped.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
character(kind=CK, len=*), | intent(in) | :: | msg |
the error message |
||
logical(kind=LK), | intent(inout), | optional | :: | found |
if the caller is handling the
exception with an optimal return
argument. If so, |
Given the path string, if the variable is present, and is a scalar, then update its value. If it is not present, then create it and set its value.
If the variable is not a scalar, an exception will be thrown.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p | |||
character(kind=CK, len=*), | intent(in) | :: | path |
path to the variable in the structure |
||
integer(kind=IK), | intent(in) | :: | val |
the new value |
||
logical(kind=LK), | intent(out) | :: | found |
if the variable was found and was a scalar. |
Given the path string, if the variable is present, and is a scalar, then update its value. If it is not present, then create it and set its value.
If the variable is not a scalar, an exception will be thrown.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p | |||
character(kind=CK, len=*), | intent(in) | :: | path |
path to the variable in the structure |
||
logical(kind=LK), | intent(in) | :: | val |
the new value |
||
logical(kind=LK), | intent(out) | :: | found |
if the variable was found and was a scalar. |
Given the path string, if the variable is present, and is a scalar, then update its value. If it is not present, then create it and set its value.
If the variable is not a scalar, an exception will be thrown.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p | |||
character(kind=CK, len=*), | intent(in) | :: | path |
path to the variable in the structure |
||
real(kind=RK), | intent(in) | :: | val |
the new value |
||
logical(kind=LK), | intent(out) | :: | found |
if the variable was found and was a scalar. |
Alternate version of json_update_real, where val
is real32
.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p | |||
character(kind=CK, len=*), | intent(in) | :: | path |
path to the variable in the structure |
||
real(kind=real32), | intent(in) | :: | val |
the new value |
||
logical(kind=LK), | intent(out) | :: | found |
if the variable was found and was a scalar. |
Given the path string, if the variable is present, and is a scalar, then update its value. If it is not present, then create it and set its value.
If the variable is not a scalar, an exception will be thrown.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p | |||
character(kind=CK, len=*), | intent(in) | :: | path |
path to the variable in the structure |
||
character(kind=CK, len=*), | intent(in) | :: | val |
the new value |
||
logical(kind=LK), | intent(out) | :: | found |
if the variable was found and was a scalar. |
||
logical(kind=LK), | intent(in), | optional | :: | trim_str |
if TRIM() should be called for the |
|
logical(kind=LK), | intent(in), | optional | :: | adjustl_str |
if ADJUSTL() should be called for the |
Alternate version of json_update_string, where path
is kind=CDK.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p | |||
character(kind=CDK, len=*), | intent(in) | :: | path |
path to the variable in the structure |
||
character(kind=CK, len=*), | intent(in) | :: | val |
the new value |
||
logical(kind=LK), | intent(out) | :: | found |
if the variable was found and was a scalar. |
||
logical(kind=LK), | intent(in), | optional | :: | trim_str |
if TRIM() should be called for the |
|
logical(kind=LK), | intent(in), | optional | :: | adjustl_str |
if ADJUSTL() should be called for the |
Alternate version of json_update_string, where val
is kind=CDK.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p | |||
character(kind=CK, len=*), | intent(in) | :: | path |
path to the variable in the structure |
||
character(kind=CDK, len=*), | intent(in) | :: | val |
the new value |
||
logical(kind=LK), | intent(out) | :: | found |
if the variable was found and was a scalar. |
||
logical(kind=LK), | intent(in), | optional | :: | trim_str |
if TRIM() should be called for the |
|
logical(kind=LK), | intent(in), | optional | :: | adjustl_str |
if ADJUSTL() should be called for the |
Returns true if the path
is present in the p
JSON structure.
Just a wrapper for json_get_by_path, so it uses the
specified path_mode
and other settings.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | intent(in), | pointer | :: | p |
a JSON linked list |
|
character(kind=CK, len=*), | intent(in) | :: | path |
path to the variable |
true if it was found
Add an integer value child to the json_value variable.
This routine is part of the public API that can be used to build a JSON structure using json_value pointers.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p | |||
character(kind=CK, len=*), | intent(in) | :: | name | |||
integer(kind=IK), | intent(in) | :: | val |
Add a integer vector child to the json_value variable.
This routine is part of the public API that can be used to build a JSON structure using json_value pointers.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p | |||
character(kind=CK, len=*), | intent(in) | :: | name |
name of the variable |
||
integer(kind=IK), | intent(in), | dimension(:) | :: | val |
value |
Add a logical value child to the json_value variable.
This routine is part of the public API that can be used to build a JSON structure using json_value pointers.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p | |||
character(kind=CK, len=*), | intent(in) | :: | name |
name of the variable |
||
logical(kind=LK), | intent(in) | :: | val |
value |
Add a logical vector child to the json_value variable.
This routine is part of the public API that can be used to build a JSON structure using json_value pointers.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p | |||
character(kind=CK, len=*), | intent(in) | :: | name |
name of the vector |
||
logical(kind=LK), | intent(in), | dimension(:) | :: | val |
value |
Adds member
as a child of p
.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p |
|
||
type(json_value), | pointer | :: | member |
the child member
to add to |
Add a NULL value child to the json_value variable.
This routine is part of the public API that can be used to build a JSON structure using json_value pointers.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p | |||
character(kind=CK, len=*), | intent(in) | :: | name |
Add a real value child to the json_value variable.
This routine is part of the public API that can be used to build a JSON structure using json_value pointers.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p | |||
character(kind=CK, len=*), | intent(in) | :: | name |
variable name |
||
real(kind=RK), | intent(in) | :: | val |
real value |
Alternate version of json_value_add_real where val
is real32
.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p | |||
character(kind=CK, len=*), | intent(in) | :: | name |
variable name |
||
real(kind=real32), | intent(in) | :: | val |
real value |
Alternate version of json_value_add_real_vec where val
is real32
.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p | |||
character(kind=CK, len=*), | intent(in) | :: | name | |||
real(kind=real32), | intent(in), | dimension(:) | :: | val |
Add a real vector child to the json_value variable.
This routine is part of the public API that can be used to build a JSON structure using json_value pointers.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p | |||
character(kind=CK, len=*), | intent(in) | :: | name | |||
real(kind=RK), | intent(in), | dimension(:) | :: | val |
Add a character string child to the json_value variable.
This routine is part of the public API that can be used to build a JSON structure using json_value pointers.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p | |||
character(kind=CK, len=*), | intent(in) | :: | name |
name of the variable |
||
character(kind=CK, len=*), | intent(in) | :: | val |
value |
||
logical(kind=LK), | intent(in), | optional | :: | trim_str |
if TRIM() should be called for the |
|
logical(kind=LK), | intent(in), | optional | :: | adjustl_str |
if ADJUSTL() should be called for the |
Alternate version of json_value_add_string where name
is kind=CDK.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p | |||
character(kind=CDK, len=*), | intent(in) | :: | name |
name of the variable |
||
character(kind=CK, len=*), | intent(in) | :: | val |
value |
||
logical(kind=LK), | intent(in), | optional | :: | trim_str |
if TRIM() should be called for the |
|
logical(kind=LK), | intent(in), | optional | :: | adjustl_str |
if ADJUSTL() should be called for the |
Alternate version of json_value_add_string where val
is kind=CDK.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p | |||
character(kind=CK, len=*), | intent(in) | :: | name |
name of the variable |
||
character(kind=CDK, len=*), | intent(in) | :: | val |
value |
||
logical(kind=LK), | intent(in), | optional | :: | trim_str |
if TRIM() should be called for the |
|
logical(kind=LK), | intent(in), | optional | :: | adjustl_str |
if ADJUSTL() should be called for the |
Add a character string vector child to the json_value variable.
This routine is part of the public API that can be used to build a JSON structure using json_value pointers.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p | |||
character(kind=CK, len=*), | intent(in) | :: | name |
variable name |
||
character(kind=CK, len=*), | intent(in), | dimension(:) | :: | val |
array of strings |
|
logical(kind=LK), | intent(in), | optional | :: | trim_str |
if TRIM() should be called for each element |
|
logical(kind=LK), | intent(in), | optional | :: | adjustl_str |
if ADJUSTL() should be called for each element |
Alternate version of json_value_add_string_vec where name
is kind=CDK.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p | |||
character(kind=CDK, len=*), | intent(in) | :: | name | |||
character(kind=CK, len=*), | intent(in), | dimension(:) | :: | val | ||
logical(kind=LK), | intent(in), | optional | :: | trim_str | ||
logical(kind=LK), | intent(in), | optional | :: | adjustl_str |
Alternate version of json_value_add_string_vec where val
is kind=CDK.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p | |||
character(kind=CK, len=*), | intent(in) | :: | name | |||
character(kind=CDK, len=*), | intent(in), | dimension(:) | :: | val | ||
logical(kind=LK), | intent(in), | optional | :: | trim_str | ||
logical(kind=LK), | intent(in), | optional | :: | adjustl_str |
Recursive deep copy function called by json_clone.
If new data is added to the json_value type, then this would need to be updated.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(json_value), | pointer | :: | from |
this is the structure to clone |
||
type(json_value), | pointer | :: | to |
the clone is put here (it must not already be associated) |
||
type(json_value), | optional, | pointer | :: | parent |
to%parent |
|
type(json_value), | optional, | pointer | :: | previous |
to%previous |
|
logical, | optional | :: | tail |
if “to” is the tail of its parent’s children |
Allocate a json_value pointer and make it an array variable. The pointer should not already be allocated.
type(json_value),pointer :: p
type(json_core) :: json
call json%create_array(p,'arrayname')
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p | |||
character(kind=CK, len=*), | intent(in) | :: | name |
Allocate a json_value pointer and make it an integer(IK) variable. The pointer should not already be allocated.
type(json_value),pointer :: p
type(json_core) :: json
call json%create_integer(p,'value',1)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p | |||
integer(kind=IK), | intent(in) | :: | val | |||
character(kind=CK, len=*), | intent(in) | :: | name |
Allocate a json_value pointer and make it a logical(LK) variable. The pointer should not already be allocated.
type(json_value),pointer :: p
type(json_core) :: json
call json%create_logical(p,'value',.true.)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p | |||
logical(kind=LK), | intent(in) | :: | val |
variable value |
||
character(kind=CK, len=*), | intent(in) | :: | name |
variable name |
Allocate a json_value pointer and make it a null variable. The pointer should not already be allocated.
type(json_value),pointer :: p
type(json_core) :: json
call json%create_null(p,'value')
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p | |||
character(kind=CK, len=*), | intent(in) | :: | name |
Allocate a json_value pointer and make it an object variable. The pointer should not already be allocated.
type(json_value),pointer :: p
type(json_core) :: json
call json%create_object(p,'objectname')
The name is not significant for the root structure or an array element. In those cases, an empty string can be used.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p | |||
character(kind=CK, len=*), | intent(in) | :: | name |
Allocate a json_value pointer and make it a real(RK) variable. The pointer should not already be allocated.
type(json_value),pointer :: p
type(json_core) :: json
call json%create_real(p,'value',1.0_RK)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p | |||
real(kind=RK), | intent(in) | :: | val | |||
character(kind=CK, len=*), | intent(in) | :: | name |
Alternate version of json_value_create_real where val=real32.
The value is converted into a real(RK)
variable internally.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p | |||
real(kind=real32), | intent(in) | :: | val | |||
character(kind=CK, len=*), | intent(in) | :: | name |
Allocate a json_value pointer and make it a string variable. The pointer should not already be allocated.
type(json_value),pointer :: p
type(json_core) :: json
call json%create_string(p,'value','hello')
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p | |||
character(kind=CK, len=*), | intent(in) | :: | val | |||
character(kind=CK, len=*), | intent(in) | :: | name | |||
logical(kind=LK), | intent(in), | optional | :: | trim_str |
if TRIM() should be called for the |
|
logical(kind=LK), | intent(in), | optional | :: | adjustl_str |
if ADJUSTL() should be called for the |
Destroy a json_value linked-list structure.
The original FSON version of this routine was not properly freeing the memory. It was rewritten.
This routine destroys this variable, it’s children, and
(if destroy_next
is true) the subsequent elements in
an object or array. It does not destroy the parent or
previous elements.
There is some protection here to enable destruction of improperly-created linked lists. However, likely there are cases not handled. Use the json_value_validate method to validate a JSON structure that was manually created using json_value pointers.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p |
variable to destroy |
||
logical(kind=LK), | intent(in), | optional | :: | destroy_next |
if true, then |
Returns pointer to the first child of the object
(or null()
if it is not associated).
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | intent(in), | pointer | :: | p |
object or array JSON data |
|
type(json_value), | pointer | :: | child |
pointer to the child |
Returns a child in the object or array given the index.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | intent(in), | pointer | :: | p |
object or array JSON data |
|
integer(kind=IK), | intent(in) | :: | idx |
index of the child (this is a 1-based Fortran style array index). |
||
type(json_value), | pointer | :: | child |
pointer to the child |
||
logical(kind=LK), | intent(out), | optional | :: | found |
true if the value was found (if not present, an exception will be thrown if it was not found. If present and not found, no exception will be thrown). |
Returns a child in the object or array given the name string.
The name search can be case-sensitive or not, and can have significant trailing whitespace or not, depending on the settings in the json_core class.
The name
input is not a path, and is not parsed like it is in json_get_by_path.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | intent(in), | pointer | :: | p | ||
character(kind=CK, len=*), | intent(in) | :: | name |
the name of a child of |
||
type(json_value), | pointer | :: | child |
pointer to the child |
||
logical(kind=LK), | intent(out), | optional | :: | found |
true if the value was found (if not present, an exception will be thrown if it was not found. If present and not found, no exception will be thrown). |
Inserts element
after p
, and updates the JSON structure accordingly.
program test
use json_module
implicit none
logical(json_LK) :: found
type(json_core) :: json
type(json_value),pointer :: p,new,element
call json%load(file='myfile.json', p=p)
call json%get(p,'x(3)',element,found) ! get pointer to an array element in the file
call json%create_integer(new,1,'') ! create a new element
call json%insert_after(element,new) ! insert new element after x(3)
call json%print(p,'myfile2.json') ! write it to a file
call json%destroy(p) ! cleanup
end program test
element
are carried along. p
[1] - [2] - [3] - [4]
|
[5] - [6] - [7] n=3 elements inserted
element last
Result is:
[1] - [2] - [5] - [6] - [7] - [3] - [4]
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p |
a value from a JSON structure (presumably, this is a child of an object or array). |
||
type(json_value), | pointer | :: | element |
the element to insert after |
Inserts element
after the idx
-th child of p
,
and updates the JSON structure accordingly. This is just
a wrapper for json_value_insert_after.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p |
a JSON object or array. |
||
integer(kind=IK), | intent(in) | :: | idx |
the index of the child of |
||
type(json_value), | pointer | :: | element |
the element to insert |
Print the JSON structure to a string or a file.
str
argument is non-optional is because of a
bug in v4.9 of the gfortran compiler.Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | intent(in), | pointer | :: | p | ||
integer(kind=IK), | intent(in) | :: | iunit |
file unit to write to (the file is assumed to be open) |
||
character(kind=CK, len=:), | intent(inout), | allocatable | :: | str |
if |
|
integer(kind=IK), | intent(in), | optional | :: | indent |
indention level |
|
logical(kind=LK), | intent(in), | optional | :: | need_comma |
if it needs a comma after it |
|
logical(kind=LK), | intent(in), | optional | :: | colon |
if the colon was just written |
|
logical(kind=LK), | intent(in), | optional | :: | is_array_element |
if this is an array element |
|
logical(kind=LK), | intent(in), | optional | :: | is_compressed_vector |
if True, this is an element from an array being printed on one line [default is False] |
|
integer(kind=IK), | intent(inout) | :: | iloc |
current index in |
Given the path string, remove the variable from json_value, if it exists.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p | |||
character(kind=CK, len=*), | intent(in) | :: | path |
the path to the variable to remove |
Rename a json_value.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | intent(in), | pointer | :: | p | ||
character(kind=CK, len=*), | intent(in) | :: | name |
new variable name |
Parse the JSON file and populate the json_value tree.
Parse the JSON file and populate the json_value tree.
The inputs can be:
file
& unit
: the specified unit is used to read JSON from file.
[note if unit is already open, then the filename is ignored]file
: JSON is read from file using internal unit number type(json_core) :: json
type(json_value),pointer :: p
call json%load(file='myfile.json', p=p)
When calling this routine, any exceptions thrown from previous calls will automatically be cleared.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
character(kind=CDK, len=*), | intent(in) | :: | file |
JSON file name |
||
type(json_value), | pointer | :: | p |
output structure |
||
integer(kind=IK), | intent(in), | optional | :: | unit |
file unit number (/= 0) |
get matrix info about a json_value
Alternate version of json_info that returns matrix information about a json_value.
A json_value is a valid rank 2 matrix if all of the following are true:
The idea here is that if it is a valid matrix, it can be interoperable with a Fortran rank 2 array of the same type.
The following example is an array with var_type=json_integer
,
n_sets=3
, and set_size=4
{
"matrix": [
[1,2,3,4],
[5,6,7,8],
[9,10,11,12]
]
}
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p |
a JSON linked list |
||
logical(kind=LK), | intent(out) | :: | is_matrix |
true if it is a valid matrix |
||
integer(kind=IK), | intent(out), | optional | :: | var_type |
variable type of data in the matrix (if all elements have the same type) |
|
integer(kind=IK), | intent(out), | optional | :: | n_sets |
number of data sets (i.e., matrix rows if using row-major order) |
|
integer(kind=IK), | intent(out), | optional | :: | set_size |
size of each data set (i.e., matrix cols if using row-major order) |
|
character(kind=CK, len=:), | intent(out), | optional, | allocatable | :: | name |
variable name |
Returns matrix information about a json_value, given the path.
If found
is present, no exceptions will be thrown if an
error occurs. Otherwise, an exception will be thrown if the
variable is not found.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p |
a JSON linked list |
||
character(kind=CK, len=*), | intent(in) | :: | path |
path to the variable |
||
logical(kind=LK), | intent(out) | :: | is_matrix |
true if it is a valid matrix |
||
logical(kind=LK), | intent(out), | optional | :: | found |
true if it was found |
|
integer(kind=IK), | intent(out), | optional | :: | var_type |
variable type of data in the matrix (if all elements have the same type) |
|
integer(kind=IK), | intent(out), | optional | :: | n_sets |
number of data sets (i.e., matrix rows if using row-major order) |
|
integer(kind=IK), | intent(out), | optional | :: | set_size |
size of each data set (i.e., matrix cols if using row-major order) |
|
character(kind=CK, len=:), | intent(out), | optional, | allocatable | :: | name |
variable name |
Alternate version of json_matrix_info_by_path where “path” is kind=CDK.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p |
a JSON linked list |
||
character(kind=CDK, len=*), | intent(in) | :: | path |
path to the variable |
||
logical(kind=LK), | intent(out) | :: | is_matrix |
true if it is a valid matrix |
||
logical(kind=LK), | intent(out), | optional | :: | found |
true if it was found |
|
integer(kind=IK), | intent(out), | optional | :: | var_type |
variable type of data in the matrix (if all elements have the same type) |
|
integer(kind=IK), | intent(out), | optional | :: | n_sets |
number of data sets (i.e., matrix rows if using row-major order) |
|
integer(kind=IK), | intent(out), | optional | :: | set_size |
size of each data set (i.e., matrix cols if using row-major order) |
|
character(kind=CK, len=:), | intent(out), | optional, | allocatable | :: | name |
variable name |
Returns true if name
is equal to p%name
, using the specified
settings for case sensitivity and trailing whitespace.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | intent(in) | :: | p |
the json object |
||
character(kind=CK, len=*), | intent(in) | :: | name |
the name to check for |
true if the string are lexically equal
Returns true if the name strings name1
is equal to name2
, using
the specified settings for case sensitivity and trailing whitespace.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
character(kind=CK, len=*), | intent(in) | :: | name1 |
the name to check |
||
character(kind=CK, len=*), | intent(in) | :: | name2 |
the name to check |
true if the string are lexically equal
Same as load
and deserialize
but only here for backward compatibility.
Parse the JSON file and populate the json_value tree.
The inputs can be:
file
& unit
: the specified unit is used to read JSON from file.
[note if unit is already open, then the filename is ignored]file
: JSON is read from file using internal unit number type(json_core) :: json
type(json_value),pointer :: p
call json%load(file='myfile.json', p=p)
When calling this routine, any exceptions thrown from previous calls will automatically be cleared.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
character(kind=CDK, len=*), | intent(in) | :: | file |
JSON file name |
||
type(json_value), | pointer | :: | p |
output structure |
||
integer(kind=IK), | intent(in), | optional | :: | unit |
file unit number (/= 0) |
Parse the JSON string and populate the json_value tree.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p |
output structure |
||
character(kind=CK, len=*), | intent(in) | :: | str |
string with JSON data |
Alternate version of json_parse_string, where str
is kind=CDK.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p |
output structure |
||
character(kind=CDK, len=*), | intent(in) | :: | str |
string with JSON data |
Core parsing routine.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
integer(kind=IK), | intent(in) | :: | unit |
file unit number (if parsing from a file) |
||
character(kind=CK, len=*), | intent(in) | :: | str |
JSON string (if parsing from a string) |
||
type(json_value), | pointer | :: | array |
An error checking routine to call after a file (or string) has been parsed. It will throw an exception if there are any other non-whitespace characters in the file.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
integer(kind=IK), | intent(in) | :: | unit |
file unit number |
||
character(kind=CK, len=*), | intent(in) | :: | str |
string containing JSON
data (only used if |
Core parsing routine.
This is used to verify the strings true
, false
, and null
during parsing.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
integer(kind=IK), | intent(in) | :: | unit |
file unit number (if parsing from a file) |
||
character(kind=CK, len=*), | intent(in) | :: | str |
JSON string (if parsing from a string) |
||
character(kind=CK, len=*), | intent(in) | :: | chars |
the string to check for. |
Read a numerical value from the file (or string). The routine will determine if it is an integer or a real, and allocate the type accordingly.
Complete rewrite of the original FSON routine, which had some problems.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
integer(kind=IK), | intent(in) | :: | unit |
file unit number (if parsing from a file) |
||
character(kind=CK, len=*), | intent(in) | :: | str |
JSON string (if parsing from a string) |
||
type(json_value), | pointer | :: | value |
Core parsing routine.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
integer(kind=IK), | intent(in) | :: | unit |
file unit number (if parsing from a file) |
||
character(kind=CK, len=*), | intent(in) | :: | str |
JSON string (if parsing from a string) |
||
type(json_value), | pointer | :: | parent |
the parsed object will be added as a child of this |
Parses a string while reading a JSON file.
string
is now returned unescaped.Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
integer(kind=IK), | intent(in) | :: | unit |
file unit number (if parsing from a file) |
||
character(kind=CK, len=*), | intent(in) | :: | str |
JSON string (if parsing from a string) |
||
character(kind=CK, len=:), | intent(out), | allocatable | :: | string |
the string (unescaped if necessary) |
Core parsing routine.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
integer(kind=IK), | intent(in) | :: | unit |
file unit number |
||
character(kind=CK, len=*), | intent(in) | :: | str |
string containing JSON
data (only used if |
||
type(json_value), | pointer | :: | value |
JSON data that is extracted |
Get the next character from the file (or string).
This routine ignores non-printing ASCII characters
(iachar<=31
) that are in strings.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
integer(kind=IK), | intent(in) | :: | unit |
file unit number (if parsing from a file) |
||
character(kind=CK, len=*), | intent(in) | :: | str |
JSON string (if parsing from a
string) – only used if |
||
logical(kind=LK), | intent(in), | optional | :: | skip_ws |
to ignore whitespace [default False] |
|
logical(kind=LK), | intent(in), | optional | :: | skip_comments |
to ignore comment lines [default False] |
|
logical(kind=LK), | intent(out) | :: | eof |
true if the end of the file has been reached. |
||
character(kind=CK, len=1), | intent(out) | :: | popped |
the popped character returned |
Internal routine to be called before parsing JSON.
Currently, all this does it allocate the comment_char
if none was specified.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json |
Print the json_value to an output unit or file.
type(json_core) :: json
type(json_value) :: p
!...
call json%print(p,'test.json') !this is json_print_to_filename
Print the json_value structure to the console (output_unit
).
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | intent(in), | pointer | :: | p |
Print the json_value structure to a file.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | intent(in), | pointer | :: | p | ||
integer(kind=IK), | intent(in) | :: | iunit |
the file unit (the file must already have been opened, can’t be -1). |
Print the json_value structure to a file.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | intent(in), | pointer | :: | p | ||
character(kind=CDK, len=*), | intent(in) | :: | filename |
the filename to print to (should not already be open) |
simply routine to print error messages
Print any error message, and then clear the exceptions.
This routine is used by the unit tests. It was originally in json_example.f90, and was moved here 2/26/2015 by Izaak Beekman.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
integer, | intent(in), | optional | :: | io_unit |
unit number for printing error message |
The same as serialize
, but only here for backward compatibility
Print the json_value structure to an allocatable string.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | intent(in), | pointer | :: | p | ||
character(kind=CK, len=:), | intent(out), | allocatable | :: | str |
prints structure to this string |
Remove a json_value from a linked-list structure.
Remove a json_value (and all its children) from a linked-list structure, preserving the rest of the structure.
To extract an object from one JSON structure, and add it to another:
type(json_core) :: json
type(json_value),pointer :: json1,json2,p
logical :: found
!create and populate json1 and json2
call json%get(json1,'name',p,found) ! get pointer to name element of json1
call json%remove(p,destroy=.false.) ! remove it from json1 (don't destroy)
call json%add(json2,p) ! add it to json2
To remove an object from a JSON structure (and destroy it):
type(json_core) :: json
type(json_value),pointer :: json1,p
logical :: found
!create and populate json1
call json%get(json1,'name',p,found) ! get pointer to name element of json1
call json%remove(p) ! remove and destroy it
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p | |||
logical(kind=LK), | intent(in), | optional | :: | destroy |
Option to destroy |
If the child variable is present, then remove it.
Given the path string, remove the variable from json_value, if it exists.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p | |||
character(kind=CK, len=*), | intent(in) | :: | path |
the path to the variable to remove |
Alternate version of json_value_remove_if_present, where path
is kind=CDK.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p | |||
character(kind=CDK, len=*), | intent(in) | :: | path |
Rename a json_value variable.
Rename a json_value.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | intent(in), | pointer | :: | p | ||
character(kind=CK, len=*), | intent(in) | :: | name |
new variable name |
Alternate version of json_value_rename, where name
is kind=CDK.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | intent(in), | pointer | :: | p | ||
character(kind=CDK, len=*), | intent(in) | :: | name |
new variable name |
Rename a json_value, given the path.
this is a wrapper for json_value_rename.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | intent(in), | pointer | :: | me | ||
character(kind=CK, len=*), | intent(in) | :: | path |
path to the variable to rename |
||
character(kind=CK, len=*), | intent(in) | :: | name |
the new name |
||
logical(kind=LK), | intent(out), | optional | :: | found |
if there were no errors |
Alternate version of json_rename_by_path, where “path” and “name” are kind=CDK
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | intent(in), | pointer | :: | me | ||
character(kind=CDK, len=*), | intent(in) | :: | path | |||
character(kind=CDK, len=*), | intent(in) | :: | name | |||
logical(kind=LK), | intent(out), | optional | :: | found |
Alternate version of json_rename_by_path, where “name” is kind=CDK
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | intent(in), | pointer | :: | me | ||
character(kind=CK, len=*), | intent(in) | :: | path | |||
character(kind=CDK, len=*), | intent(in) | :: | name | |||
logical(kind=LK), | intent(out), | optional | :: | found |
Alternate version of json_rename_by_path, where “path” is kind=CDK
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | intent(in), | pointer | :: | me | ||
character(kind=CDK, len=*), | intent(in) | :: | path | |||
character(kind=CK, len=*), | intent(in) | :: | name | |||
logical(kind=LK), | intent(out), | optional | :: | found |
Replace a json_value in a linked-list structure.
Replace p1
with p2
in a JSON structure.
The replacement is done using an insert and remove See json_value_insert_after and json_value_remove for details.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p1 |
the item to replace |
||
type(json_value), | pointer | :: | p2 |
item to take the place of |
||
logical(kind=LK), | intent(in), | optional | :: | destroy |
Should |
Reverse the order of the children of an array of object.
Reverse the order of the children of an array or object.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p |
Print the json_value structure to an allocatable string
Print the json_value structure to an allocatable string.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | intent(in), | pointer | :: | p | ||
character(kind=CK, len=:), | intent(out), | allocatable | :: | str |
prints structure to this string |
get string info about a json_value
Returns information about character strings returned from a json_value.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p | |||
integer(kind=IK), | intent(out), | optional, | dimension(:), allocatable | :: | ilen |
if |
integer(kind=IK), | intent(out), | optional | :: | max_str_len |
The maximum length required to
hold the string representation returned
by a call to a |
|
logical(kind=LK), | intent(out), | optional | :: | found |
true if there were no errors. if not present, an error will throw an exception |
Convert a string into a real(RK)
value.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
character(kind=CK, len=*), | intent(in) | :: | str |
a string |
str
converted to a real(RK)
Convert a string into an integer.
Replacement for the parse_integer
function in the original code.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
character(kind=CK, len=*), | intent(in) | :: | str |
a string |
str
converted to an integer
Swap two json_value pointers in a structure (or two different structures).
Swap two elements in a JSON structure. All of the children are carried along as well.
If both are not associated, then an error is thrown.
The assumption here is that both variables are part of a valid
json_value linked list (so the normal parent
, previous
,
next
, etc. pointers are properly associated if necessary).
This cannot be used to swap a parent/child pair, since that could lead to a circular linkage. An exception is thrown if this is tried.
There are also other situations where using this routine may produce a malformed JSON structure, such as moving an array element outside of an array. This is not checked for.
If p1
and p2
have a common parent, it is always safe to swap them.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p1 |
swap with |
||
type(json_value), | pointer | :: | p2 |
swap with |
Throw an exception.
Throw an exception in the json_core. This routine sets the error flag, and prevents any subsequent routine from doing anything, until json_clear_exceptions is called.
If is_verbose
is true, this will also print a
traceback if the Intel compiler is used.
If stop_on_error
is true, then the program is stopped.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
character(kind=CK, len=*), | intent(in) | :: | msg |
the error message |
||
logical(kind=LK), | intent(inout), | optional | :: | found |
if the caller is handling the
exception with an optimal return
argument. If so, |
Alternate version of json_throw_exception, where msg
is kind=CDK.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
character(kind=CDK, len=*), | intent(in) | :: | msg |
the error message |
||
logical(kind=LK), | intent(inout), | optional | :: | found |
if the caller is handling the
exception with an optimal return
argument. If so, |
Change the json_value variable to an array.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p | |||
character(kind=CK, len=*), | intent(in), | optional | :: | name |
if the name is also to be changed. |
Change the json_value variable to an integer.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p | |||
integer(kind=IK), | intent(in), | optional | :: | val |
if the value is also to be set (if not present, then 0 is used). |
|
character(kind=CK, len=*), | intent(in), | optional | :: | name |
if the name is also to be changed. |
Change the json_value variable to a logical.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p | |||
logical(kind=LK), | intent(in), | optional | :: | val |
if the value is also to be set (if not present, then .false. is used). |
|
character(kind=CK, len=*), | intent(in), | optional | :: | name |
if the name is also to be changed. |