json_traverse Subroutine

public recursivesubroutine json_traverse(me, traverse_callback)

Arguments

Type IntentOptional AttributesName
type(json_value), intent(in), pointer:: me
procedure(traverse_callback_func) :: traverse_callback

Description

Traverse a JSON structure. This routine calls the user-specified traverse_callback_func for each element of the structure.

Calls

proc~~json_traverse~~CallsGraph proc~json_traverse json_traverse proc~json_traverse->proc~json_traverse proc~json_count json_count proc~json_traverse->proc~json_count
Help

Called By

proc~~json_traverse~~CalledByGraph proc~json_traverse json_traverse proc~json_traverse->proc~json_traverse proc~test_14 test_14 proc~test_14->proc~json_traverse program~jf_test_14 jf_test_14 program~jf_test_14->proc~test_14
Help

Variables

TypeVisibility AttributesNameInitial
type(json_value), public, pointer:: element

a child element

integer(kind=IK), public :: i

counter

integer(kind=IK), public :: icount

number of children

logical(kind=LK), public :: finished

can be used to stop the process


Source Code

    recursive subroutine json_traverse(me,traverse_callback)

    implicit none

    type(json_value),pointer,intent(in) :: me
    procedure(traverse_callback_func)   :: traverse_callback

    type(json_value),pointer :: element  !! a child element
    integer(IK) :: i        !! counter
    integer(IK) :: icount   !! number of children
    logical(LK) :: finished !! can be used to stop the process

    if (exception_thrown) return

    call traverse_callback(me,finished) ! first call for this object
    if (finished) return

    !for arrays and objects, have to also call for all children:
    if (me%var_type==json_array .or. me%var_type==json_object) then

        icount = json_count(me) ! number of children
        if (icount>0) then
            element => me%children  ! first one
            do i = 1, icount        ! call for each child
                call json_traverse(element,traverse_callback)
                if (finished) exit
                element => element%next
            end do
        end if
        nullify(element)

    end if

    end subroutine json_traverse