@@ -3078,33 +3078,47 @@ subroutine json_value_add_member(json,p,member)
3078
3078
implicit none
3079
3079
3080
3080
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`
3084
3083
type (json_value),pointer :: member ! ! the child member
3085
3084
! ! to add to `p`
3086
3085
3086
+ integer (IK) :: var_type ! ! variable type of `p`
3087
+
3087
3088
if (.not. json% exception_thrown) then
3088
3089
3089
- ! associate the parent
3090
- member% parent = > p
3090
+ if (associated (p)) then
3091
3091
3092
- ! add to linked list
3093
- if (associated (p% children)) then
3092
+ call json% info(p,var_type= var_type)
3094
3093
3095
- p % tail % next = > member
3096
- member % previous = > p % tail
3094
+ select case (var_type)
3095
+ case (json_object, json_array)
3097
3096
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
3099
3108
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
3102
3112
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
3104
3117
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
3108
3122
3109
3123
end if
3110
3124
0 commit comments