test_8 Subroutine

public subroutine test_8(error_cnt)

Arguments

Type IntentOptional AttributesName
integer, intent(out) :: error_cnt

Description

read a JSON structure from a string

Calls

proc~~test_8~~CallsGraph proc~test_8 test_8 interface~json_print json_print proc~test_8->interface~json_print proc~json_failed json_failed proc~test_8->proc~json_failed interface~json_destroy json_destroy proc~test_8->interface~json_destroy proc~json_print_error_message json_print_error_message proc~test_8->proc~json_print_error_message proc~json_initialize json_initialize proc~test_8->proc~json_initialize interface~json_parse json_parse proc~test_8->interface~json_parse proc~json_print_1 json_print_1 interface~json_print->proc~json_print_1 proc~json_print_2 json_print_2 interface~json_print->proc~json_print_2 proc~json_value_destroy json_value_destroy interface~json_destroy->proc~json_value_destroy proc~json_check_for_errors json_check_for_errors proc~json_print_error_message->proc~json_check_for_errors proc~json_clear_exceptions json_clear_exceptions proc~json_print_error_message->proc~json_clear_exceptions interface~throw_exception throw_exception proc~json_initialize->interface~throw_exception proc~json_initialize->proc~json_clear_exceptions proc~json_parse_file json_parse_file interface~json_parse->proc~json_parse_file proc~json_parse_string json_parse_string interface~json_parse->proc~json_parse_string proc~json_value_print json_value_print proc~json_print_1->proc~json_value_print proc~json_print_1->interface~throw_exception proc~json_print_2->interface~json_print proc~json_print_2->interface~throw_exception proc~json_value_print->proc~json_value_print proc~json_value_print->interface~throw_exception proc~real_to_string real_to_string proc~json_value_print->proc~real_to_string proc~json_count json_count proc~json_value_print->proc~json_count proc~integer_to_string integer_to_string proc~json_value_print->proc~integer_to_string none~write_it write_it proc~json_value_print->none~write_it proc~json_throw_exception json_throw_exception interface~throw_exception->proc~json_throw_exception proc~compact_real_string compact_real_string proc~real_to_string->proc~compact_real_string proc~json_value_destroy->proc~json_value_destroy proc~destroy_json_data destroy_json_data proc~json_value_destroy->proc~destroy_json_data proc~json_parse_file->proc~json_initialize proc~json_parse_file->interface~throw_exception proc~annotate_invalid_json annotate_invalid_json proc~json_parse_file->proc~annotate_invalid_json proc~parse_value parse_value proc~json_parse_file->proc~parse_value proc~json_value_create json_value_create proc~json_parse_file->proc~json_value_create proc~json_parse_string->proc~json_initialize proc~json_parse_string->proc~annotate_invalid_json proc~json_parse_string->proc~parse_value proc~json_parse_string->proc~json_value_create proc~annotate_invalid_json->proc~integer_to_string proc~get_current_line_from_file_sequential get_current_line_from_file_sequential proc~annotate_invalid_json->proc~get_current_line_from_file_sequential proc~get_current_line_from_file_stream get_current_line_from_file_stream proc~annotate_invalid_json->proc~get_current_line_from_file_stream proc~parse_value->interface~throw_exception proc~to_string to_string proc~parse_value->proc~to_string proc~parse_array parse_array proc~parse_value->proc~parse_array proc~pop_char pop_char proc~parse_value->proc~pop_char proc~parse_number parse_number proc~parse_value->proc~parse_number proc~parse_string parse_string proc~parse_value->proc~parse_string proc~to_logical to_logical proc~parse_value->proc~to_logical proc~push_char push_char proc~parse_value->proc~push_char proc~to_object to_object proc~parse_value->proc~to_object proc~to_array to_array proc~parse_value->proc~to_array proc~parse_for_chars parse_for_chars proc~parse_value->proc~parse_for_chars proc~to_null to_null proc~parse_value->proc~to_null proc~parse_object parse_object proc~parse_value->proc~parse_object proc~to_string->proc~destroy_json_data proc~parse_array->interface~json_destroy proc~parse_array->interface~throw_exception proc~parse_array->proc~parse_value proc~parse_array->proc~json_value_create proc~parse_array->proc~pop_char interface~json_add json_add proc~parse_array->interface~json_add proc~parse_number->interface~throw_exception proc~parse_number->proc~pop_char proc~parse_number->proc~push_char proc~to_double to_double proc~parse_number->proc~to_double proc~to_integer to_integer proc~parse_number->proc~to_integer proc~string_to_integer string_to_integer proc~parse_number->proc~string_to_integer proc~string_to_double string_to_double proc~parse_number->proc~string_to_double proc~parse_string->interface~throw_exception proc~parse_string->proc~pop_char proc~valid_json_hex valid_json_hex proc~parse_string->proc~valid_json_hex proc~to_logical->proc~destroy_json_data proc~push_char->interface~throw_exception proc~push_char->proc~integer_to_string proc~to_object->proc~destroy_json_data proc~to_array->proc~destroy_json_data proc~parse_for_chars->interface~throw_exception proc~parse_for_chars->proc~pop_char proc~to_null->proc~destroy_json_data proc~parse_object->interface~json_destroy proc~parse_object->interface~throw_exception proc~parse_object->proc~parse_value proc~parse_object->proc~json_value_create proc~parse_object->proc~pop_char proc~parse_object->proc~parse_string proc~parse_object->proc~parse_object proc~parse_object->interface~json_add proc~json_value_add_logical json_value_add_logical interface~json_add->proc~json_value_add_logical proc~json_value_add_double json_value_add_double interface~json_add->proc~json_value_add_double proc~json_value_add_member json_value_add_member interface~json_add->proc~json_value_add_member proc~json_value_add_integer json_value_add_integer interface~json_add->proc~json_value_add_integer proc~json_value_add_double_vec json_value_add_double_vec interface~json_add->proc~json_value_add_double_vec proc~json_value_add_logical_vec json_value_add_logical_vec interface~json_add->proc~json_value_add_logical_vec proc~json_value_add_integer_vec json_value_add_integer_vec interface~json_add->proc~json_value_add_integer_vec proc~json_value_add_string_vec json_value_add_string_vec interface~json_add->proc~json_value_add_string_vec proc~json_value_add_string json_value_add_string interface~json_add->proc~json_value_add_string proc~json_value_add_logical->proc~json_value_create proc~json_value_add_logical->proc~to_logical proc~json_value_add_logical->interface~json_add proc~json_value_add_double->proc~json_value_create proc~json_value_add_double->interface~json_add proc~json_value_add_double->proc~to_double proc~json_value_add_integer->proc~json_value_create proc~json_value_add_integer->interface~json_add proc~json_value_add_integer->proc~to_integer proc~json_value_add_double_vec->proc~json_value_create proc~json_value_add_double_vec->proc~to_array proc~json_value_add_double_vec->interface~json_add proc~json_value_add_logical_vec->proc~json_value_create proc~json_value_add_logical_vec->proc~to_array proc~json_value_add_logical_vec->interface~json_add proc~json_value_add_integer_vec->proc~json_value_create proc~json_value_add_integer_vec->proc~to_array proc~json_value_add_integer_vec->interface~json_add proc~json_value_add_string_vec->proc~json_value_create proc~json_value_add_string_vec->proc~to_array proc~json_value_add_string_vec->interface~json_add proc~json_value_add_string->proc~json_value_create proc~json_value_add_string->proc~to_string proc~json_value_add_string->interface~json_add proc~escape_string escape_string proc~json_value_add_string->proc~escape_string proc~to_double->proc~destroy_json_data proc~to_integer->proc~destroy_json_data proc~string_to_integer->interface~throw_exception proc~string_to_double->interface~throw_exception
Help

Called By

proc~~test_8~~CalledByGraph proc~test_8 test_8 program~jf_test_8 jf_test_8 program~jf_test_8->proc~test_8
Help

Variables

TypeVisibility AttributesNameInitial
type(json_value), public, pointer:: p
character(len=*), public, parameter:: newline =achar(10)
character(len=*), public, parameter:: str ='{ "label": "foo",'//newline//' "value": "bar" }'
character(len=*), public, parameter:: str2 ='{ "label": "foo",'//newline//'  "value": "bar",'//newline//'  "empty_array": [],'//newline//'  "empty_object": {}'//newline//'}'
character(len=*), public, parameter:: str_invalid ='{ "label": "foo",'//newline//' "value : "bar" }'

Source Code

    subroutine test_8(error_cnt)

    !! read a JSON structure from a string

    implicit none

    integer,intent(out) :: error_cnt

    type(json_value),pointer :: p

    character(len=*),parameter :: newline = achar(10)

    character(len=*),parameter :: str = '{ "label": "foo",'//newline//' "value": "bar" }'

    character(len=*),parameter :: str2 = '{ "label": "foo",'//newline//&
                                         '  "value": "bar",'//newline//&
                                         '  "empty_array": [],'//newline//&
                                         '  "empty_object": {}' //newline//&
                                         '}'

    character(len=*),parameter :: str_invalid = '{ "label": "foo",'//newline//' "value : "bar" }'

    error_cnt = 0
    call json_initialize()
    if (json_failed()) then
        call json_print_error_message(error_unit)
        error_cnt = error_cnt + 1
    end if

    write(error_unit,'(A)') ''
    write(error_unit,'(A)') '================================='
    write(error_unit,'(A)') '   EXAMPLE 8 : read JSON from string'
    write(error_unit,'(A)') '================================='
    write(error_unit,'(A)') ''

    write(error_unit,'(A)') '**************'
    write(error_unit,'(A)') ' Valid test 1:'
    write(error_unit,'(A)') '**************'
    write(error_unit,'(A)') ''
    call json_parse(str=str, p=p)   ! read it from str
    if (json_failed()) then
        call json_print_error_message(error_unit)
        error_cnt = error_cnt + 1
    end if
    write(output_unit,'(A)') '{ "part a" : '
    call json_print(p,output_unit)  ! print to console
    write(output_unit,'(A)') ','
    if (json_failed()) then
        call json_print_error_message(error_unit)
        error_cnt = error_cnt + 1
    end if
    call json_destroy(p)            ! cleanup
    if (json_failed()) then
        call json_print_error_message(error_unit)
        error_cnt = error_cnt + 1
    end if
    write(error_unit,'(A)') ''

    write(error_unit,'(A)') '**************'
    write(error_unit,'(A)') ' Valid test 2:'
    write(error_unit,'(A)') '**************'
    write(error_unit,'(A)') ''
    call json_parse(str=str2, p=p)   ! read it from str
    if (json_failed()) then
        call json_print_error_message(error_unit)
        error_cnt = error_cnt + 1
    end if
    write(output_unit,'(A)') '"part b" : '
    call json_print(p,output_unit)  ! print to console
    write(output_unit,'(A)') ','
    if (json_failed()) then
        call json_print_error_message(error_unit)
        error_cnt = error_cnt + 1
    end if
    call json_destroy(p)            ! cleanup
    if (json_failed()) then
        call json_print_error_message(error_unit)
        error_cnt = error_cnt + 1
    end if
    write(error_unit,'(A)') ''

    write(error_unit,'(A)') '**************'
    write(error_unit,'(A)') ' Invalid test:'
    write(error_unit,'(A)') '**************'
    write(error_unit,'(A)') ''
    call json_parse(str=str_invalid, p=p)   ! read it from str
    if (json_failed()) then
        call json_print_error_message(error_unit)
    else
        write(error_unit,'(A)') 'This should have failed!'
        error_cnt = error_cnt + 1
    end if
    write(output_unit,'(A)') '"part c" : '
    call json_print(p,output_unit)  ! print to console
    write(output_unit,'(A)') '}'
    if (json_failed()) then
        call json_print_error_message(error_unit)
        error_cnt = error_cnt + 1
    end if
    call json_destroy(p)            ! cleanup
    if (json_failed()) then
        call json_print_error_message(error_unit)
        error_cnt = error_cnt + 1
    end if
    write(error_unit,'(A)') ''

    end subroutine test_8