Given the path string, if the variable is present, and is a scalar, then update its value. If it is not present, then create it and set its value.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p | |||
character(kind=CK,len=*), | intent(in) | :: | path | |||
character(kind=CK,len=*), | intent(in) | :: | val | |||
logical(kind=LK), | intent(out) | :: | found |
Nodes of different colours represent the following:
Solid arrows point from a procedure to one which it calls. Dashed arrows point from an interface to procedures which implement that interface. This could include the module procedures in a generic interface or the implementation in a submodule of an interface in a parent module. Where possible, edges connecting nodes are given different colours to make them easier to distinguish in large graphs.
subroutine json_update_string(json,p,path,val,found)
implicit none
class(json_core),intent(inout) :: json
type(json_value),pointer :: p
character(kind=CK,len=*),intent(in) :: path
character(kind=CK,len=*),intent(in) :: val
logical(LK),intent(out) :: found
type(json_value),pointer :: p_var
integer(IK) :: var_type
call json%get(p,path,p_var,found)
if (found) then
call json%info(p_var,var_type)
select case (var_type)
case (json_null,json_logical,json_integer,json_double,json_string)
call to_string(p_var,val) !update the value
case default
found = .false.
call json%throw_exception('Error in json_update_string: '//&
'the variable is not a scalar value')
end select
else
call json%add_by_path(p,path,val) !add the new element
end if
end subroutine json_update_string