Skip to content

Commit 6fc47be

Browse files
committed
minor changes and added a new unit test with escape characters.
1 parent 0a422d2 commit 6fc47be

File tree

3 files changed

+21
-12
lines changed

3 files changed

+21
-12
lines changed

files/inputs/test1.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"a": {
1818
"b": 1
1919
},
20+
"escape": " \" \\ \/ \b \f \n \r \t ",
2021
"empty_array": [],
2122
"empty_object": {},
2223
"empty_string": "",

src/json_value_module.F90

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6721,7 +6721,7 @@ subroutine json_get_path(json, p, path, found, use_alt_array_tokens, path_sep)
67216721

67226722
!get info about the current variable:
67236723
call json%info(tmp,name=name)
6724-
if (json%path_mode==2) then
6724+
if (json%path_mode==2_IK) then
67256725
name = encode_rfc6901(name)
67266726
end if
67276727

@@ -6731,7 +6731,7 @@ subroutine json_get_path(json, p, path, found, use_alt_array_tokens, path_sep)
67316731
!get info about the parent:
67326732
call json%info(tmp%parent,var_type=var_type,&
67336733
n_children=n_children,name=parent_name)
6734-
if (json%path_mode==2) then
6734+
if (json%path_mode==2_IK) then
67356735
parent_name = encode_rfc6901(parent_name)
67366736
end if
67376737

@@ -6758,19 +6758,19 @@ subroutine json_get_path(json, p, path, found, use_alt_array_tokens, path_sep)
67586758
end if
67596759
end do
67606760
select case(json%path_mode)
6761-
case(3)
6761+
case(3_IK)
67626762
! JSONPath "bracket-notation"
67636763
! example: `$['key'][1]`
67646764
! [note: this uses 1-based indices]
67656765
call integer_to_string(i,int_fmt,istr)
67666766
call add_to_path(start_array//single_quote//parent_name//&
67676767
single_quote//end_array//&
67686768
start_array//trim(adjustl(istr))//end_array,CK_'')
6769-
case(2)
6769+
case(2_IK)
67706770
! rfc6901
67716771
call integer_to_string(i-1,int_fmt,istr) ! 0-based index
67726772
call add_to_path(parent_name//slash//trim(adjustl(istr)))
6773-
case(1)
6773+
case(1_IK)
67746774
! default
67756775
call integer_to_string(i,int_fmt,istr)
67766776
if (use_brackets) then
@@ -6787,7 +6787,7 @@ subroutine json_get_path(json, p, path, found, use_alt_array_tokens, path_sep)
67876787

67886788
!process parent on the next pass
67896789
select case(json%path_mode)
6790-
case(3)
6790+
case(3_IK)
67916791
call add_to_path(start_array//single_quote//name//&
67926792
single_quote//end_array,CK_'')
67936793
case default
@@ -6807,7 +6807,7 @@ subroutine json_get_path(json, p, path, found, use_alt_array_tokens, path_sep)
68076807
else
68086808
!the last one:
68096809
select case(json%path_mode)
6810-
case(3)
6810+
case(3_IK)
68116811
call add_to_path(start_array//single_quote//name//&
68126812
single_quote//end_array,CK_'')
68136813
case default
@@ -6836,10 +6836,10 @@ subroutine json_get_path(json, p, path, found, use_alt_array_tokens, path_sep)
68366836
path = CK_''
68376837
else
68386838
select case (json%path_mode)
6839-
case(3)
6839+
case(3_IK)
68406840
! add the outer level object identifier:
68416841
path = root//path
6842-
case(2)
6842+
case(2_IK)
68436843
! add the root slash:
68446844
path = slash//path
68456845
end select
@@ -6866,21 +6866,21 @@ subroutine add_to_path(str,path_sep)
68666866
!! (ignored if `json%path_mode/=1`)
68676867

68686868
select case (json%path_mode)
6869-
case(3)
6869+
case(3_IK)
68706870
! in this case, the options are ignored
68716871
if (.not. allocated(path)) then
68726872
path = str
68736873
else
68746874
path = str//path
68756875
end if
6876-
case(2)
6876+
case(2_IK)
68776877
! in this case, the options are ignored
68786878
if (.not. allocated(path)) then
68796879
path = str
68806880
else
68816881
path = str//slash//path
68826882
end if
6883-
case(1)
6883+
case(1_IK)
68846884
! default path format
68856885
if (.not. allocated(path)) then
68866886
path = str

src/tests/jf_test_1.f90

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,14 @@ subroutine test_1(error_cnt)
153153
else
154154
write(error_unit,'(A)') 'data(1).array(2) = '//trim(cval)
155155
end if
156+
write(error_unit,'(A)') ''
157+
call json%get('escape', cval)
158+
if (json%failed()) then
159+
call json%print_error_message(error_unit)
160+
error_cnt = error_cnt + 1
161+
else
162+
write(error_unit,'(A)') 'escape = '//trim(cval)
163+
end if
156164

157165
! get a logical value:
158166
call json%get('data(1).tf1', lval)

0 commit comments

Comments
 (0)