@@ -276,15 +276,27 @@ module json_module
276
276
!
277
277
! # Example
278
278
!
279
+ ! The following test program:
279
280
! ```fortran
281
+ ! program test
282
+ ! use json_module
283
+ ! implicit none
280
284
! type(json_value),pointer :: p
281
- ! call json_create_object(p,'') !root
282
- ! call json_add(p,'year',1805)
283
- ! call json_add(p,'value',1.0d0)
284
- ! call json_print(p,'test.json')
285
- ! call json_destroy(p)
285
+ ! call json_initialize() !initialize the module
286
+ ! call json_create_object(p,'') !create the root
287
+ ! call json_add(p,'year',1805) !add some data
288
+ ! call json_add(p,'value',1.0d0) !add some data
289
+ ! call json_print(p,'test.json') !write it to a file
290
+ ! call json_destroy(p) !cleanup
291
+ ! end program test
292
+ ! ```
293
+ ! Produces the JSON file **test.json**:
294
+ ! ```json
295
+ ! {
296
+ ! "year": 1805,
297
+ ! "value": 0.1E+1
298
+ ! }
286
299
! ```
287
- !
288
300
type,public :: json_value
289
301
290
302
! force the constituents to be stored contiguously
@@ -325,25 +337,29 @@ module json_module
325
337
! # Example
326
338
!
327
339
! ```fortran
340
+ ! program test
341
+ ! use json_module
342
+ ! implicit none
328
343
! type(json_file) :: json
329
344
! integer :: ival
330
345
! real(real64) :: rval
331
346
! character(len=:),allocatable :: cval
332
347
! logical :: found
348
+ ! call json_initialize()
333
349
! call json%load_file(filename='myfile.json')
334
350
! call json%print_file() !print to the console
335
351
! call json%get('var.i',ival,found)
336
352
! call json%get('var.r(3)',rval,found)
337
353
! call json%get('var.c',cval,found)
338
354
! call json%destroy()
355
+ ! end program test
339
356
! ```
340
357
341
358
type,public :: json_file
342
359
343
360
private
344
361
345
- ! the JSON structure read from the file:
346
- type (json_value),pointer :: p = > null ()
362
+ type (json_value),pointer :: p = > null () ! ! the JSON structure read from the file
347
363
348
364
contains
349
365
0 commit comments