@@ -168,7 +168,7 @@ module json_value_module
168168 logical (LK) :: is_verbose = .false. ! ! if true, all exceptions are
169169 ! ! immediately printed to console.
170170
171- logical (LK) :: stop_on_error = .false. ! ! if true, then the program is
171+ logical (LK) :: stop_on_error = .false. ! ! if true, then the program is
172172 ! ! stopped immediately when an
173173 ! ! exception is raised.
174174
@@ -3078,33 +3078,47 @@ subroutine json_value_add_member(json,p,member)
30783078 implicit none
30793079
30803080 class(json_core),intent (inout ) :: json
3081- type (json_value),pointer :: p ! ! `p` should be a `json_object`
3082- ! ! or a `json_array` (although this
3083- ! ! is not currently checked)
3081+ type (json_value),pointer :: p ! ! `p` must be a `json_object`
3082+ ! ! or a `json_array`
30843083 type (json_value),pointer :: member ! ! the child member
30853084 ! ! to add to `p`
30863085
3086+ integer (IK) :: var_type ! ! variable type of `p`
3087+
30873088 if (.not. json% exception_thrown) then
30883089
3089- ! associate the parent
3090- member% parent = > p
3090+ if (associated (p)) then
30913091
3092- ! add to linked list
3093- if (associated (p% children)) then
3092+ call json% info(p,var_type= var_type)
30943093
3095- p % tail % next = > member
3096- member % previous = > p % tail
3094+ select case (var_type)
3095+ case (json_object, json_array)
30973096
3098- else
3097+ ! associate the parent
3098+ member% parent = > p
3099+
3100+ ! add to linked list
3101+ if (associated (p% children)) then
3102+ p% tail% next = > member
3103+ member% previous = > p% tail
3104+ else
3105+ p% children = > member
3106+ member% previous = > null () ! first in the list
3107+ end if
30993108
3100- p% children = > member
3101- member% previous = > null () ! first in the list
3109+ ! new member is now the last one in the list
3110+ p% tail = > member
3111+ p% n_children = p% n_children + 1
31023112
3103- end if
3113+ case default
3114+ call json% throw_exception(' Error in json_value_add_member: ' // &
3115+ ' can only add child to object or array' )
3116+ end select
31043117
3105- ! new member is now the last one in the list
3106- p% tail = > member
3107- p% n_children = p% n_children + 1
3118+ else
3119+ call json% throw_exception(' Error in json_value_add_member: ' // &
3120+ ' the pointer is not associated' )
3121+ end if
31083122
31093123 end if
31103124
@@ -5687,10 +5701,11 @@ end function wrap_json_valid_path
56875701! >
56885702! Returns the [[json_value]] pointer given the path string.
56895703!
5690- ! It uses either of two methods:
5704+ ! It uses one of three methods:
56915705!
56925706! * The original JSON-Fortran defaults
56935707! * [RFC 6901](https://tools.ietf.org/html/rfc6901)
5708+ ! * [JSONPath](http://goessner.net/articles/JsonPath/) "bracket-notation"
56945709
56955710 subroutine json_get_by_path (json , me , path , p , found )
56965711
@@ -5710,7 +5725,6 @@ subroutine json_get_by_path(json, me, path, p, found)
57105725
57115726 if (.not. json% exception_thrown) then
57125727
5713- ! note: it can only be 1 or 2 (3 not currently enabled)
57145728 select case (json% path_mode)
57155729 case (1_IK )
57165730 call json% json_get_by_path_default(me, path, p, found)
@@ -6294,8 +6308,9 @@ end subroutine json_get_by_path_default
62946308! are user-specified. To fully conform to the RFC 6901 standard,
62956309! should probably set (via `initialize`):
62966310!
6297- ! * `trailing_spaces_significant` = .true. [this is not the default setting]
6298- ! * `case_sensitive_keys` = .true. [this is the default setting]
6311+ ! * `case_sensitive_keys = .true.` [this is the default setting]
6312+ ! * `trailing_spaces_significant = .true.` [this is *not* the default setting]
6313+ ! * `allow_duplicate_keys = .false.` [this is *not* the default setting]
62996314!
63006315! ### Example
63016316!
@@ -6440,7 +6455,7 @@ subroutine json_get_by_path_rfc6901(json, me, path, p, found)
64406455 end if
64416456 if (status_ok) then
64426457 ! if we make it this far, it should be
6443- ! convertable to an integer, so do it.
6458+ ! convertible to an integer, so do it.
64446459 call string_to_integer(token,ival,status_ok)
64456460 end if
64466461 end if
@@ -6739,6 +6754,7 @@ subroutine json_get_by_path_jsonpath_bracket(json,me,path,p,found,create_it,was_
67396754
67406755 ! verify that there are no spaces or other
67416756 ! characters in the string:
6757+ status_ok = .true.
67426758 do i= 1 ,len (token)
67436759 ! It must only contain (0..9) characters
67446760 ! (it must be unsigned)
@@ -9875,7 +9891,7 @@ subroutine parse_string(json, unit, str, string)
98759891 ! start accumulating the hex string (should be the next 4 characters)
98769892 if (escape) then
98779893 escape = .false.
9878- is_hex = (c==' u' ) ! the next four characters are the hex string
9894+ is_hex = (c== CK_ ' u' ) ! the next four characters are the hex string
98799895 else
98809896 escape = (c== backslash)
98819897 end if
0 commit comments