json_get_scalar_by_path.inc 842 Bytes
Newer Older
Victor Yu's avatar
Victor Yu committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
    type(json_value),pointer :: p

    if (present(default)) then
        value = default
    else
        value = default_if_not_specified
    end if

    if ( json%exception_thrown ) then
       call flag_not_found(found)
       return
    end if

    nullify(p)
    call json%get(me=me, path=path, p=p)

    if (.not. associated(p)) then
        call json%throw_exception('Error in '//routine//':'//&
                                  ' Unable to resolve path: '// trim(path),found)
    else
        call json%get(p,value)
    end if

    if ( json%exception_thrown ) then
        if ( present(found) .or. present(default)) then
            call flag_not_found(found)
            if (present(default)) value = default
            call json%clear_exceptions()
        end if
    else
        if ( present(found) ) found = .true.
    end if