json_count Function

private function json_count(json, p) result(count)

Count the number of children in the object or array.

History

  • JW : 1/4/2014 : Original routine removed. Now using n_children variable. Renamed from json_value_count.

Arguments

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

this should normally be a json_object or a json_array. For any other variable type this will return 0.

Return Value integer(kind=IK)

number of children in p.


Contents

Source Code


Source Code

    function json_count(json,p) result(count)

    implicit none

    class(json_core),intent(inout)      :: json
    type(json_value),pointer,intent(in) :: p      !! this should normally be a `json_object`
                                                  !! or a `json_array`. For any other
                                                  !! variable type this will return 0.
    integer(IK)                         :: count  !! number of children in `p`.

    if (associated(p)) then
        count = p%n_children
    else
        call json%throw_exception('Error in json_count: '//&
                                  'pointer is not associated.')
    end if

    end function json_count