json_value Derived Type

type, public :: json_value
sequence

Type used to construct the linked-list JSON structure. Normally, this should always be a pointer variable. This type should only be used by an instance of json_core.

Example

The following test program:

    program test
     use json_module
     implicit none
     type(json_core) :: json
     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_RK) !add some data
     call json%print(p,'test.json')  !write it to a file
     call json%destroy(p)            !cleanup
    end program test

Produces the JSON file test.json:

    {
      "year": 1805,
      "value": 0.1E+1
    }

Warning

Pointers of this type should only be allocated using the methods from json_core.


Inherited by

type~~json_value~~InheritedByGraph type~json_value json_value type~json_value->type~json_value previous, next, parent, children, tail type~json_file json_file type~json_file->type~json_value p

Components

Type Visibility Attributes Name Initial
type(json_value), private, pointer :: children => null()

first child item of this

real(kind=RK), private, allocatable :: dbl_value

real data for this variable

integer(kind=IK), private, allocatable :: int_value

integer data for this variable

logical(kind=LK), private, allocatable :: log_value

logical data for this variable

integer(kind=IK), private :: n_children = 0

number of children

character(kind=CK, len=:), private, allocatable :: name

variable name (unescaped)

type(json_value), private, pointer :: next => null()

next item in the list

type(json_value), private, pointer :: parent => null()

parent item of this

type(json_value), private, pointer :: previous => null()

previous item in the list

character(kind=CK, len=:), private, allocatable :: str_value

string data for this variable (unescaped)

type(json_value), private, pointer :: tail => null()

last child item of this

integer(kind=IK), private :: var_type = json_unknown

variable type


Source Code

    type,public :: json_value

        !force the constituents to be stored contiguously
        ![note: on Intel, the order of the variables below
        ! is significant to avoid the misaligned field warnings]
        sequence

        private

        !for the linked list:
        type(json_value),pointer :: previous => null()  !! previous item in the list
        type(json_value),pointer :: next     => null()  !! next item in the list
        type(json_value),pointer :: parent   => null()  !! parent item of this
        type(json_value),pointer :: children => null()  !! first child item of this
        type(json_value),pointer :: tail     => null()  !! last child item of this

        character(kind=CK,len=:),allocatable :: name  !! variable name (unescaped)

        real(RK),allocatable                 :: dbl_value  !! real data for this variable
        logical(LK),allocatable              :: log_value  !! logical data for this variable
        character(kind=CK,len=:),allocatable :: str_value  !! string data for this variable
                                                           !! (unescaped)
        integer(IK),allocatable              :: int_value  !! integer data for this variable

        integer(IK) :: var_type = json_unknown  !! variable type

        integer(IK),private :: n_children = 0   !! number of children

    end type json_value