@@ -100,25 +100,26 @@ of pointers. See the json_example.f90 file for more examples.
100100
101101``` fortran
102102 program example2
103+
104+ use,intrinsic :: iso_fortran_env, only: wp => real64
103105
104106 use json_module
105107
106- type(json_value),pointer :: p, inp
108+ type(json_value),pointer :: p, inp
107109 logical :: found
108- integer :: iunit
109110
110111 ! initialize the module
111112 call json_initialize()
112113
113114 ! initialize the structure:
114115 call json_value_create(p)
115- call to_object(p,'test2.json' )
116+ call to_object(p)
116117
117118 ! add an "inputs" object to the structure:
118119 call json_value_create(inp)
119120 call to_object(inp,'inputs')
120121 call json_value_add(p, inp) !add it to the root
121-
122+
122123 ! add some data to inputs:
123124 call json_value_add(inp, 't0', 0.1_wp)
124125 call json_value_add(inp, 'tf', 1.1_wp)
@@ -129,18 +130,45 @@ of pointers. See the json_example.f90 file for more examples.
129130 call json_value_add(inp, 'logical_scalar', .true.)
130131 call json_value_add(inp, 'logical_vector', [.true., .false., .true.])
131132 nullify(inp) !don't need this anymore
132-
133+
133134 ! write the file:
134- open(newunit=iunit, file='test2.json', status='REPLACE')
135- call json_print(p,iunit)
136- close(iunit)
135+ call json_print(p,'test2.json')
137136
138137 !cleanup:
139138 call json_destroy(p)
140-
139+
141140 end program example2
142141```
143142
143+ The code above produces the file:
144+
145+ ``` Python
146+ {
147+ " inputs" : {
148+ " t0" : 0.1000000000000000E+000 ,
149+ " tf" : 0.1100000000000000E+001 ,
150+ " x0" : 0.9999000000000000E+004 ,
151+ " integer_scalar" : 787 ,
152+ " integer_array" : [
153+ 2 ,
154+ 4 ,
155+ 99
156+ ],
157+ " names" : [
158+ " aaa" ,
159+ " bbb" ,
160+ " ccc"
161+ ],
162+ " logical_scalar" : true,
163+ " logical_vector" : [
164+ true,
165+ false,
166+ true
167+ ]
168+ }
169+ }
170+ ```
171+
144172Documentation
145173--------------
146174
0 commit comments