@@ -2965,6 +2965,8 @@ subroutine json_value_insert_after_child_by_index(json,p,idx,element)
29652965 type (json_value),pointer :: p ! ! a JSON object or array.
29662966 integer (IK),intent (in ) :: idx ! ! the index of the child of `p` to
29672967 ! ! insert the new element after
2968+ ! ! (this is a 1-based Fortran
2969+ ! ! style array index)
29682970 type (json_value),pointer :: element ! ! the element to insert
29692971
29702972 type (json_value),pointer :: tmp ! ! for getting the `idx`-th child of `p`
@@ -6228,6 +6230,15 @@ subroutine json_get_integer_vec(json, me, vec)
62286230
62296231 logical (LK) :: initialized
62306232
6233+ ! check for 0-length arrays first:
6234+ select case (me% var_type)
6235+ case (json_array)
6236+ if (json% count (me)==0 ) then
6237+ allocate (vec(0 ))
6238+ return
6239+ end if
6240+ end select
6241+
62316242 initialized = .false.
62326243
62336244 ! the callback function is called for each element of the array:
@@ -6440,6 +6451,15 @@ subroutine json_get_double_vec(json, me, vec)
64406451
64416452 logical (LK) :: initialized
64426453
6454+ ! check for 0-length arrays first:
6455+ select case (me% var_type)
6456+ case (json_array)
6457+ if (json% count (me)==0 ) then
6458+ allocate (vec(0 ))
6459+ return
6460+ end if
6461+ end select
6462+
64436463 initialized = .false.
64446464
64456465 ! the callback function is called for each element of the array:
@@ -6648,6 +6668,15 @@ subroutine json_get_logical_vec(json, me, vec)
66486668
66496669 logical (LK) :: initialized
66506670
6671+ ! check for 0-length arrays first:
6672+ select case (me% var_type)
6673+ case (json_array)
6674+ if (json% count (me)==0 ) then
6675+ allocate (vec(0 ))
6676+ return
6677+ end if
6678+ end select
6679+
66516680 initialized = .false.
66526681
66536682 ! the callback function is called for each element of the array:
@@ -6920,6 +6949,15 @@ subroutine json_get_string_vec(json, me, vec)
69206949
69216950 logical (LK) :: initialized
69226951
6952+ ! check for 0-length arrays first:
6953+ select case (me% var_type)
6954+ case (json_array)
6955+ if (json% count (me)==0 ) then
6956+ allocate (vec(0 ))
6957+ return
6958+ end if
6959+ end select
6960+
69236961 initialized = .false.
69246962
69256963 ! the callback function is called for each element of the array:
@@ -7043,6 +7081,16 @@ subroutine json_get_alloc_string_vec(json, me, vec, ilen)
70437081 logical (LK) :: initialized ! ! if the output array has been sized
70447082 integer (IK) :: max_len ! ! the length of the longest string in the array
70457083
7084+ ! check for 0-length arrays first:
7085+ select case (me% var_type)
7086+ case (json_array)
7087+ if (json% count (me)==0 ) then
7088+ allocate (character (kind= CK,len= 0 ) :: vec(0 ))
7089+ allocate (ilen(0 ))
7090+ return
7091+ end if
7092+ end select
7093+
70467094 initialized = .false.
70477095
70487096 call json% string_info(me,ilen= ilen,max_str_len= max_len)
0 commit comments