Add a string value to a json_value, given the path.
Warning
If the path points to an existing variable in the structure, then this routine will destroy it and replace it with the new value.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | me |
the JSON structure |
||
character(kind=CK, len=*), | intent(in) | :: | path |
the path to the variable |
||
character(kind=CK, len=*), | intent(in) | :: | value |
the value to add |
||
logical(kind=LK), | intent(out), | optional | :: | found |
if the variable was found |
|
logical(kind=LK), | intent(out), | optional | :: | was_created |
if the variable had to be created |
|
logical(kind=LK), | intent(in), | optional | :: | trim_str |
if TRIM() should be called for each element |
|
logical(kind=LK), | intent(in), | optional | :: | adjustl_str |
if ADJUSTL() should be called for each element |
subroutine json_add_string_by_path(json,me,path,value,found,& was_created,trim_str,adjustl_str) implicit none class(json_core),intent(inout) :: json type(json_value),pointer :: me !! the JSON structure character(kind=CK,len=*),intent(in) :: path !! the path to the variable character(kind=CK,len=*),intent(in) :: value !! the value to add logical(LK),intent(out),optional :: found !! if the variable was found logical(LK),intent(out),optional :: was_created !! if the variable had to be created logical(LK),intent(in),optional :: trim_str !! if TRIM() should be called for each element logical(LK),intent(in),optional :: adjustl_str !! if ADJUSTL() should be called for each element type(json_value),pointer :: p type(json_value),pointer :: tmp character(kind=CK,len=:),allocatable :: name !! variable name if ( .not. json%exception_thrown ) then nullify(p) ! return a pointer to the path (possibly creating it) ! If the variable had to be created, then ! it will be a json_null variable. call json%create(me,path,p,found,was_created) if (.not. associated(p)) then call json%throw_exception('Error in json_add_string_by_path:'//& ' Unable to resolve path: '//trim(path),found) if (present(found)) then found = .false. call json%clear_exceptions() end if else !NOTE: a new object is created, and the old one ! is replaced and destroyed. This is to ! prevent memory leaks if the type is ! being changed (for example, if an array ! is being replaced with a scalar). if (p%var_type==json_string) then p%str_value = value else call json%info(p,name=name) call json%create_string(tmp,value,name,trim_str,adjustl_str) call json%replace(p,tmp,destroy=.true.) end if end if else if ( present(found) ) found = .false. if ( present(was_created) ) was_created = .false. end if end subroutine json_add_string_by_path