change all "name" variable values to "Fred"
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | intent(in), | pointer | :: | p | ||
logical, | intent(out) | :: | finished |
subroutine rename(json,p,finished) !! change all "name" variable values to "Fred"
implicit none
class(json_core),intent(inout) :: json
type(json_value),pointer,intent(in) :: p
logical,intent(out) :: finished
integer :: var_type
character(kind=json_CK,len=:),allocatable :: str
logical :: found
!get info about this variable:
call json%info(p,var_type=var_type,name=str)
!it must be a string named "name":
if (var_type==json_string .and. str=='name') then
call json%get(p,'@',str) ! get original name
call json%update(p,'@',new_name,found) ! change it
write(error_unit,'(A)') str//' name changed to '//new_name
icount = icount + 1
end if
!cleanup:
if (allocated(str)) deallocate(str)
!always false, since we want to traverse all nodes:
finished = .false.
end subroutine rename