version 0.6.0
JSON writer

Data Types

type  mod_json_writer::t_json
 JSON container. More...
 

Functions/Subroutines

subroutine mod_json_writer::json_up (json)
 Return to parent object. More...
 

Detailed Description

JSON writer conform to RFC 7159 (https://tools.ietf.org/html/rfc7159).

Example:

type(t_json) :: json
integer :: json_unit
! Generate an object without label
call json%add_object("")
! Generate an object "type" inside of previous object
call json%add_object("type")
! Generate 5 values of different types
call json%add("integer", 1)
call json%add("double", 1d0)
call json%add("string", "one")
call json%add("boolean", .true.)
call json%add("null")
! Return to parent object
call json%up()
! Generate an object "arrays" after the "type" object
call json%add_object("arrays")
! Generate 4 arrays of different types
call json%add("integer_array", [1, 2, 3])
call json%add("double_array", [1d0, 2d0, 3d0])
call json%add("string_array", ["one", "two", "tri"])
call json%add("boolean_array", [.true., .false., .true.])
! Open a file
open(newunit=json_unit, file="example.json", status="replace")
! Write the JSON container into the file "example.json". Note the 'DT' format.
write(json_unit,'(DT)') json
! Close the file
close(json_unit)
! Free memory
call json%finalize()

Expected output:

{
"type": {
"integer": 1,
"double": 1.0000000000000000,
"string": "one",
"boolean": true,
"null": null
},
"arrays": {
"integer_array": [
1,
2,
3
],
"double_array": [
1.0000000000000000,
2.0000000000000000,
3.0000000000000000
],
"string_array": [
"one",
"two",
"tri"
],
"boolean_array": [
true,
false,
true
]
}
}

Function/Subroutine Documentation

◆ json_up()

subroutine mod_json_writer::json_up ( class(t_json), intent(inout)  json)
Parameters
[in,out]jsonJSON container