@@ -208,15 +208,18 @@ module json_value_module
208208 ! ! `allow_comments` is true.
209209 ! ! Examples: '`!`' or '`#`'.
210210
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]])
214217
215218 character (kind= CK,len= 1 ) :: path_separator = dot ! ! The `path` separator to use
216219 ! ! in the "default" mode for
217220 ! ! the paths in the various
218221 ! ! `get_by_path` routines.
219- ! ! Note: if `use_rfc6901_paths=true `
222+ ! ! Note: if `path_mode/=1 `
220223 ! ! then this is ignored.
221224
222225 contains
@@ -660,7 +663,7 @@ function initialize_json_core(verbose,compact_reals,&
660663 no_whitespace ,&
661664 unescape_strings ,&
662665 comment_char ,&
663- use_rfc6901_paths ,&
666+ path_mode ,&
664667 path_separator ) result(json_core_object)
665668
666669 implicit none
@@ -676,7 +679,7 @@ function initialize_json_core(verbose,compact_reals,&
676679 no_whitespace,&
677680 unescape_strings,&
678681 comment_char,&
679- use_rfc6901_paths ,&
682+ path_mode ,&
680683 path_separator)
681684
682685 end function initialize_json_core
@@ -709,7 +712,7 @@ subroutine json_initialize(json,verbose,compact_reals,&
709712 no_whitespace ,&
710713 unescape_strings ,&
711714 comment_char ,&
712- use_rfc6901_paths ,&
715+ path_mode ,&
713716 path_separator )
714717
715718 implicit none
@@ -756,8 +759,14 @@ subroutine json_initialize(json,verbose,compact_reals,&
756759 json% no_whitespace = no_whitespace
757760 if (present (unescape_strings)) &
758761 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
761770
762771 ! if we are allowing comments in the file:
763772 if (present (comment_char)) then
@@ -3884,11 +3893,13 @@ subroutine json_get_by_path(json, me, path, p, found)
38843893 ! ! specify by `path`
38853894 logical (LK),intent (out ),optional :: found ! ! true if it was found
38863895
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 )
38903899 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
38923903
38933904 end subroutine json_get_by_path
38943905! *****************************************************************************************
@@ -3912,7 +3923,7 @@ end subroutine json_get_by_path
39123923! * `$` - root
39133924! * `@` - this
39143925! * `.` - 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)
39163927!
39173928! Thus, if any of these characters are present in the name key,
39183929! this routine cannot be used to get the value.
@@ -4312,8 +4323,8 @@ end subroutine wrap_json_get_by_path
43124323! `found` is present, which will be set to `false`. `path`
43134324! will be a blank string.
43144325!
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 .
43174328
43184329 subroutine json_get_path (json , p , path , found , use_alt_array_tokens , path_sep )
43194330
@@ -4389,10 +4400,11 @@ subroutine json_get_path(json, p, path, found, use_alt_array_tokens, path_sep)
43894400 exit
43904401 end if
43914402 end do
4392- if (json% use_rfc6901_paths) then
4403+ select case (json% path_mode)
4404+ case (2 )
43934405 call integer_to_string(i-1 ,int_fmt,istr) ! 0-based index
43944406 call add_to_path(parent_name// slash// trim (adjustl (istr)))
4395- else
4407+ case ( 1 )
43964408 call integer_to_string(i,int_fmt,istr)
43974409 if (use_brackets) then
43984410 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)
44014413 call add_to_path(parent_name// start_array_alt// &
44024414 trim (adjustl (istr))// end_array_alt,path_sep)
44034415 end if
4404- end if
4416+ end select
44054417 tmp = > tmp% parent ! already added parent name
44064418
44074419 case (json_object)
@@ -4444,7 +4456,7 @@ subroutine json_get_path(json, p, path, found, use_alt_array_tokens, path_sep)
44444456 if (json% exception_thrown) then
44454457 path = CK_' '
44464458 else
4447- if (json% use_rfc6901_paths ) then
4459+ if (json% path_mode == 2 ) then
44484460 ! add the root slash:
44494461 path = slash// path
44504462 end if
@@ -4468,16 +4480,17 @@ subroutine add_to_path(str,path_sep)
44684480 character (kind= CK,len=* ),intent (in ) :: str ! ! string to prepend to `path`
44694481 character (kind= CK,len= 1 ),intent (in ),optional :: path_sep
44704482 ! ! path separator (default is '.').
4471- ! ! (ignored if `json%use_rfc6901_paths=.true. `)
4483+ ! ! (ignored if `json%path_mode/=1 `)
44724484
4473- if (json% use_rfc6901_paths) then
4485+ select case (json% path_mode)
4486+ case (2 )
44744487 ! in this case, the options are ignored
44754488 if (path== CK_' ' ) then
44764489 path = str
44774490 else
44784491 path = str// slash// path
44794492 end if
4480- else
4493+ case ( 1 )
44814494 ! default path format
44824495 if (path== CK_' ' ) then
44834496 path = str
@@ -4490,7 +4503,7 @@ subroutine add_to_path(str,path_sep)
44904503 path = str// json% path_separator// path
44914504 end if
44924505 end if
4493- end if
4506+ end select
44944507
44954508 end subroutine add_to_path
44964509
0 commit comments