Skip to content

Commit 28dc281

Browse files
authoredJun 26, 2016
Merge pull request #214 from jacobwilliams/null
API for adding a null variable
2 parents a1bac70 + 1e46b80 commit 28dc281

File tree

3 files changed

+54
-3
lines changed

3 files changed

+54
-3
lines changed
 

‎files/inputs/test2.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
true,
2020
false,
2121
true
22-
]
22+
],
23+
"null_variable": null
2324
},
2425
"trajectory": [
2526
{

‎src/json_value_module.F90

+47-2
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ module json_value_module
227227
!>
228228
! Add objects to a linked list of [[json_value]]s.
229229
generic,public :: add => json_value_add_member, &
230+
MAYBEWRAP(json_value_add_null), &
230231
MAYBEWRAP(json_value_add_integer), &
231232
MAYBEWRAP(json_value_add_integer_vec), &
232233
MAYBEWRAP(json_value_add_double), &
@@ -244,6 +245,7 @@ module json_value_module
244245

245246
procedure,private :: json_value_add_member
246247
procedure,private :: MAYBEWRAP(json_value_add_integer)
248+
procedure,private :: MAYBEWRAP(json_value_add_null)
247249
procedure,private :: MAYBEWRAP(json_value_add_integer_vec)
248250
procedure,private :: MAYBEWRAP(json_value_add_double)
249251
procedure,private :: MAYBEWRAP(json_value_add_double_vec)
@@ -1943,8 +1945,8 @@ subroutine json_value_validate(json,p,is_valid,error_msg)
19431945
class(json_core),intent(inout) :: json
19441946
type(json_value),pointer,intent(in) :: p
19451947
logical(LK),intent(out) :: is_valid !! True if the structure is valid.
1946-
character(kind=CK,len=:),allocatable :: error_msg !! if not valid, this will contain
1947-
!! a description of the problem
1948+
character(kind=CK,len=:),allocatable,intent(out) :: error_msg !! if not valid, this will contain
1949+
!! a description of the problem
19481950

19491951
if (associated(p)) then
19501952
is_valid = .true.
@@ -2581,6 +2583,49 @@ subroutine wrap_json_value_add_double_vec(json, p, name, val)
25812583
end subroutine wrap_json_value_add_double_vec
25822584
!*****************************************************************************************
25832585

2586+
!*****************************************************************************************
2587+
!>
2588+
! Add a NULL value child to the [[json_value]] variable
2589+
!
2590+
!@note This routine is part of the public API that can be
2591+
! used to build a JSON structure using [[json_value]] pointers.
2592+
2593+
subroutine json_value_add_null(json, p, name)
2594+
2595+
implicit none
2596+
2597+
class(json_core),intent(inout) :: json
2598+
type(json_value),pointer :: p
2599+
character(kind=CK,len=*),intent(in) :: name
2600+
2601+
type(json_value),pointer :: var
2602+
2603+
!create the variable:
2604+
call json%create_null(var,name)
2605+
2606+
!add it:
2607+
call json%add(p, var)
2608+
2609+
end subroutine json_value_add_null
2610+
!*****************************************************************************************
2611+
2612+
!*****************************************************************************************
2613+
!>
2614+
! Alternate version of [[json_value_add_null]] where `name` is kind=CDK.
2615+
2616+
subroutine wrap_json_value_add_null(json, p, name)
2617+
2618+
implicit none
2619+
2620+
class(json_core),intent(inout) :: json
2621+
type(json_value),pointer :: p
2622+
character(kind=CDK,len=*),intent(in) :: name !! name of the variable
2623+
2624+
call json%add(p, to_unicode(name))
2625+
2626+
end subroutine wrap_json_value_add_null
2627+
!*****************************************************************************************
2628+
25842629
!*****************************************************************************************
25852630
!> author: Jacob Williams
25862631
! date: 1/20/2014

‎src/tests/jf_test_2.f90

+5
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,11 @@ subroutine test_2(error_cnt)
133133
call json%print_error_message(error_unit)
134134
error_cnt = error_cnt + 1
135135
end if
136+
call json%add(inp, 'null_variable')
137+
if (json%failed()) then
138+
call json%print_error_message(error_unit)
139+
error_cnt = error_cnt + 1
140+
end if
136141
nullify(inp)
137142

138143
!trajectory variables:

0 commit comments

Comments
 (0)
Please sign in to comment.