json_value_add_member Subroutine

private subroutine json_value_add_member(json, p, member)

Adds member as a child of p.

Arguments

Type IntentOptional AttributesName
class(json_core), intent(inout) :: json
type(json_value), pointer:: p

p should be a json_object or a json_array (although this is not currently checked)

type(json_value), pointer:: member

the child member to add to p


Contents

Source Code


Source Code

    subroutine json_value_add_member(json,p,member)

    implicit none

    class(json_core),intent(inout) :: json
    type(json_value),pointer       :: p       !! `p` should be a `json_object`
                                              !! or a `json_array` (although this
                                              !! is not currently checked)
    type(json_value),pointer       :: member  !! the child member
                                              !! to add to `p`

    if (.not. json%exception_thrown) then

        ! associate the parent
        member%parent => p

        ! add to linked list
        if (associated(p%children)) then

            p%tail%next => member
            member%previous => p%tail

        else

            p%children => member
            member%previous => null()  !first in the list

        end if

        ! new member is now the last one in the list
        p%tail => member
        p%n_children = p%n_children + 1

    end if

    end subroutine json_value_add_member