@@ -208,15 +208,18 @@ module json_value_module
208
208
! ! `allow_comments` is true.
209
209
! ! Examples: '`!`' or '`#`'.
210
210
211
- logical (LK) :: use_rfc6901_paths = .false. ! ! use the RFC 6901 standard for
212
- ! ! JSON paths. Otherwise, the original
213
- ! ! default method is used
211
+ integer (IK) :: path_mode = 1_IK ! ! How the path strings are interpreted in the
212
+ ! ! `get_by_path` routines:
213
+ ! !
214
+ ! ! * 1 -- Default mode (see [[json_get_by_path_default]])
215
+ ! ! * 2 -- as RFC 6901 "JSON Pointer" paths
216
+ ! ! (see [[json_get_by_path_rfc6901]])
214
217
215
218
character (kind= CK,len= 1 ) :: path_separator = dot ! ! The `path` separator to use
216
219
! ! in the "default" mode for
217
220
! ! the paths in the various
218
221
! ! `get_by_path` routines.
219
- ! ! Note: if `use_rfc6901_paths=true `
222
+ ! ! Note: if `path_mode/=1 `
220
223
! ! then this is ignored.
221
224
222
225
contains
@@ -660,7 +663,7 @@ function initialize_json_core(verbose,compact_reals,&
660
663
no_whitespace ,&
661
664
unescape_strings ,&
662
665
comment_char ,&
663
- use_rfc6901_paths ,&
666
+ path_mode ,&
664
667
path_separator ) result(json_core_object)
665
668
666
669
implicit none
@@ -676,7 +679,7 @@ function initialize_json_core(verbose,compact_reals,&
676
679
no_whitespace,&
677
680
unescape_strings,&
678
681
comment_char,&
679
- use_rfc6901_paths ,&
682
+ path_mode ,&
680
683
path_separator)
681
684
682
685
end function initialize_json_core
@@ -709,7 +712,7 @@ subroutine json_initialize(json,verbose,compact_reals,&
709
712
no_whitespace ,&
710
713
unescape_strings ,&
711
714
comment_char ,&
712
- use_rfc6901_paths ,&
715
+ path_mode ,&
713
716
path_separator )
714
717
715
718
implicit none
@@ -756,8 +759,14 @@ subroutine json_initialize(json,verbose,compact_reals,&
756
759
json% no_whitespace = no_whitespace
757
760
if (present (unescape_strings)) &
758
761
json% unescaped_strings = unescape_strings
759
- if (present (use_rfc6901_paths)) &
760
- json% use_rfc6901_paths = use_rfc6901_paths
762
+ if (present (path_mode)) then
763
+ if (path_mode== 1_IK .or. path_mode== 2_IK ) then
764
+ json% path_mode = path_mode
765
+ else
766
+ json% path_mode = 1_IK ! just to have a valid value
767
+ call json% throw_exception(' Invalid path_mode.' )
768
+ end if
769
+ end if
761
770
762
771
! if we are allowing comments in the file:
763
772
if (present (comment_char)) then
@@ -3884,11 +3893,13 @@ subroutine json_get_by_path(json, me, path, p, found)
3884
3893
! ! specify by `path`
3885
3894
logical (LK),intent (out ),optional :: found ! ! true if it was found
3886
3895
3887
- if (json % use_rfc6901_paths) then
3888
- call json% json_get_by_path_rfc6901(me, path, p, found )
3889
- else
3896
+ ! note: it can only be 1 or 2 (which was checked in initialize)
3897
+ select case ( json% path_mode )
3898
+ case ( 1_IK )
3890
3899
call json% json_get_by_path_default(me, path, p, found)
3891
- end if
3900
+ case (2_IK )
3901
+ call json% json_get_by_path_rfc6901(me, path, p, found)
3902
+ end select
3892
3903
3893
3904
end subroutine json_get_by_path
3894
3905
! *****************************************************************************************
@@ -3912,7 +3923,7 @@ end subroutine json_get_by_path
3912
3923
! * `$` - root
3913
3924
! * `@` - this
3914
3925
! * `.` - child object member (note this can be changed using `json%path_separator`)
3915
- ! * `[]` or `()` - child array element
3926
+ ! * `[]` or `()` - child array element (note that indices are 1-based)
3916
3927
!
3917
3928
! Thus, if any of these characters are present in the name key,
3918
3929
! this routine cannot be used to get the value.
@@ -4312,8 +4323,8 @@ end subroutine wrap_json_get_by_path
4312
4323
! `found` is present, which will be set to `false`. `path`
4313
4324
! will be a blank string.
4314
4325
!
4315
- ! @note If `json%use_rfc6901_paths=.true. `, then the
4316
- ! `use_alt_array_tokens` and `path_sep` inputs are ignored.
4326
+ ! @note If `json%path_mode/=1 `, then the `use_alt_array_tokens`
4327
+ ! and `path_sep` inputs are ignored if present .
4317
4328
4318
4329
subroutine json_get_path (json , p , path , found , use_alt_array_tokens , path_sep )
4319
4330
@@ -4389,10 +4400,11 @@ subroutine json_get_path(json, p, path, found, use_alt_array_tokens, path_sep)
4389
4400
exit
4390
4401
end if
4391
4402
end do
4392
- if (json% use_rfc6901_paths) then
4403
+ select case (json% path_mode)
4404
+ case (2 )
4393
4405
call integer_to_string(i-1 ,int_fmt,istr) ! 0-based index
4394
4406
call add_to_path(parent_name// slash// trim (adjustl (istr)))
4395
- else
4407
+ case ( 1 )
4396
4408
call integer_to_string(i,int_fmt,istr)
4397
4409
if (use_brackets) then
4398
4410
call add_to_path(parent_name// start_array// &
@@ -4401,7 +4413,7 @@ subroutine json_get_path(json, p, path, found, use_alt_array_tokens, path_sep)
4401
4413
call add_to_path(parent_name// start_array_alt// &
4402
4414
trim (adjustl (istr))// end_array_alt,path_sep)
4403
4415
end if
4404
- end if
4416
+ end select
4405
4417
tmp = > tmp% parent ! already added parent name
4406
4418
4407
4419
case (json_object)
@@ -4444,7 +4456,7 @@ subroutine json_get_path(json, p, path, found, use_alt_array_tokens, path_sep)
4444
4456
if (json% exception_thrown) then
4445
4457
path = CK_' '
4446
4458
else
4447
- if (json% use_rfc6901_paths ) then
4459
+ if (json% path_mode == 2 ) then
4448
4460
! add the root slash:
4449
4461
path = slash// path
4450
4462
end if
@@ -4468,16 +4480,17 @@ subroutine add_to_path(str,path_sep)
4468
4480
character (kind= CK,len=* ),intent (in ) :: str ! ! string to prepend to `path`
4469
4481
character (kind= CK,len= 1 ),intent (in ),optional :: path_sep
4470
4482
! ! path separator (default is '.').
4471
- ! ! (ignored if `json%use_rfc6901_paths=.true. `)
4483
+ ! ! (ignored if `json%path_mode/=1 `)
4472
4484
4473
- if (json% use_rfc6901_paths) then
4485
+ select case (json% path_mode)
4486
+ case (2 )
4474
4487
! in this case, the options are ignored
4475
4488
if (path== CK_' ' ) then
4476
4489
path = str
4477
4490
else
4478
4491
path = str// slash// path
4479
4492
end if
4480
- else
4493
+ case ( 1 )
4481
4494
! default path format
4482
4495
if (path== CK_' ' ) then
4483
4496
path = str
@@ -4490,7 +4503,7 @@ subroutine add_to_path(str,path_sep)
4490
4503
path = str// json% path_separator// path
4491
4504
end if
4492
4505
end if
4493
- end if
4506
+ end select
4494
4507
4495
4508
end subroutine add_to_path
4496
4509
0 commit comments