json_create_by_path Subroutine

private subroutine json_create_by_path(json, me, path, p, found, was_created)

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 path_mode=1 or path_mode=3. An error will be thrown for path_mode=2 (RFC 6901).

See also

Arguments

TypeIntentOptionalAttributesName
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 path

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)


Calls

proc~~json_create_by_path~~CallsGraph proc~json_create_by_path json_create_by_path proc~integer_to_string integer_to_string proc~json_create_by_path->proc~integer_to_string

Contents

Source Code


Source Code

    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
    character(kind=CK,len=max_integer_str_len) :: path_mode_str !! string version
                                                                !! of `json%path_mode`

    if (present(p)) nullify(p)

    if (.not. json%exception_thrown) then

        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(3_IK)
           call json%json_get_by_path_jsonpath_bracket(me,path,tmp,found,&
                                                       create_it=.true.,&
                                                       was_created=was_created)
           if (present(p)) p => tmp

        case default

            if (json%path_mode==2_IK) then
                ! 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('Error in json_create_by_path: '//&
                                          'Create by path not supported in RFC 6901 path mode.')
            else
                call integer_to_string(json%path_mode,int_fmt,path_mode_str)
                call json%throw_exception('Error in json_create_by_path: Unsupported path_mode: '//&
                                            trim(path_mode_str))
            end if
            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