Returns a child in the object or array given the name string.
The name search can be case-sensitive or not, and can have significant trailing whitespace or not, depending on the settings in the json_core class.
The name
input is not a path, and is not parsed like it is in json_get_by_path.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | intent(in), | pointer | :: | p | ||
character(kind=CK,len=*), | intent(in) | :: | name | the name of a child of |
||
type(json_value), | pointer | :: | child | pointer to the child |
subroutine json_value_get_by_name_chars(json, p, name, child)
implicit none
class(json_core),intent(inout) :: json
type(json_value),pointer,intent(in) :: p
character(kind=CK,len=*),intent(in) :: name !! the name of a child of `p`
type(json_value),pointer :: child !! pointer to the child
integer(IK) :: i,n_children
nullify(child)
if (.not. json%exception_thrown) then
if (associated(p)) then
if (p%var_type==json_object) then
n_children = json%count(p)
child => p%children !start with first one
do i=1, n_children
if (.not. associated(child)) then
call json%throw_exception('Error in json_value_get_by_name_chars: '//&
'Malformed JSON linked list')
return
end if
if (allocated(child%name)) then
!name string matching routine:
if (json%name_equal(child,name)) return
end if
child => child%next
end do
end if
!did not find anything:
call json%throw_exception('Error in json_value_get_by_name_chars: '//&
'child variable '//trim(name)//' was not found.')
nullify(child)
else
call json%throw_exception('Error in json_value_get_by_name_chars: '//&
'pointer is not associated.')
end if
end if
end subroutine json_value_get_by_name_chars