@@ -2965,6 +2965,8 @@ subroutine json_value_insert_after_child_by_index(json,p,idx,element)
2965
2965
type (json_value),pointer :: p ! ! a JSON object or array.
2966
2966
integer (IK),intent (in ) :: idx ! ! the index of the child of `p` to
2967
2967
! ! insert the new element after
2968
+ ! ! (this is a 1-based Fortran
2969
+ ! ! style array index)
2968
2970
type (json_value),pointer :: element ! ! the element to insert
2969
2971
2970
2972
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)
6228
6230
6229
6231
logical (LK) :: initialized
6230
6232
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
+
6231
6242
initialized = .false.
6232
6243
6233
6244
! the callback function is called for each element of the array:
@@ -6440,6 +6451,15 @@ subroutine json_get_double_vec(json, me, vec)
6440
6451
6441
6452
logical (LK) :: initialized
6442
6453
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
+
6443
6463
initialized = .false.
6444
6464
6445
6465
! the callback function is called for each element of the array:
@@ -6648,6 +6668,15 @@ subroutine json_get_logical_vec(json, me, vec)
6648
6668
6649
6669
logical (LK) :: initialized
6650
6670
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
+
6651
6680
initialized = .false.
6652
6681
6653
6682
! the callback function is called for each element of the array:
@@ -6920,6 +6949,15 @@ subroutine json_get_string_vec(json, me, vec)
6920
6949
6921
6950
logical (LK) :: initialized
6922
6951
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
+
6923
6961
initialized = .false.
6924
6962
6925
6963
! 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)
7043
7081
logical (LK) :: initialized ! ! if the output array has been sized
7044
7082
integer (IK) :: max_len ! ! the length of the longest string in the array
7045
7083
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
+
7046
7094
initialized = .false.
7047
7095
7048
7096
call json% string_info(me,ilen= ilen,max_str_len= max_len)
0 commit comments