Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(json_value), | intent(in), | pointer | :: | me | ||
procedure(traverse_callback_func), | intent(inout) | :: | traverse_callback |
Traverse a JSON structure. This routine calls the user-specified traverse_callback_func for each element of the structure.
Type | Visibility | Attributes | Name | Initial | |||
---|---|---|---|---|---|---|---|
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 |
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