Returns the json_value pointer given the path string, If necessary, by creating the variables as needed.
By default, the leaf node and any empty array elements
are created as json_null
values.
It only works for the default path mode. An error will be thrown if RFC 6901 mode is enabled.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | intent(in), | pointer | :: | me | a JSON linked list |
|
character(kind=CK,len=*), | intent(in) | :: | path | path to the variable |
||
type(json_value), | intent(out), | optional | pointer | :: | p | pointer to the variable
specify by |
logical(kind=LK), | intent(out), | optional | :: | found | true if there were no errors (variable found or created) |
|
logical(kind=LK), | intent(out), | optional | :: | was_created | true if it was actually created (as opposed to already being there) |
subroutine json_create_by_path(json,me,path,p,found,was_created)
implicit none
class(json_core),intent(inout) :: json
type(json_value),pointer,intent(in) :: me !! a JSON linked list
character(kind=CK,len=*),intent(in) :: path !! path to the variable
type(json_value),pointer,intent(out),optional :: p !! pointer to the variable
!! specify by `path`
logical(LK),intent(out),optional :: found !! true if there were no errors
!! (variable found or created)
logical(LK),intent(out),optional :: was_created !! true if it was actually created
!! (as opposed to already being there)
type(json_value),pointer :: tmp
if (present(p)) nullify(p)
if (.not. json%exception_thrown) then
! note: path_mode can only be 1 or 2 (which was checked in initialize)
select case (json%path_mode)
case(1_IK)
call json%json_get_by_path_default(me,path,tmp,found,&
create_it=.true.,&
was_created=was_created)
if (present(p)) p => tmp
case(2_IK)
! the problem here is there isn't really a way to disambiguate
! the array elements, so '/a/0' could be 'a(1)' or 'a.0'.
call json%throw_exception('Create by path not supported in RFC 6901 path mode.')
if (present(found)) then
call json%clear_exceptions()
found = .false.
end if
if (present(was_created)) was_created = .false.
end select
else
if (present(was_created)) was_created = .false.
if (present(found)) found = .false.
end if
end subroutine json_create_by_path