JSON writer conform to RFC 7159 (https://tools.ietf.org/html/rfc7159).
Example:
type(t_json) :: json
integer :: json_unit
call json%add_object("")
call json%add_object("type")
call json%add("integer", 1)
call json%add("double", 1d0)
call json%add("string", "one")
call json%add("boolean", .true.)
call json%add("null")
call json%up()
call json%add_object("arrays")
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(newunit=json_unit, file="example.json", status="replace")
write(json_unit,'(DT)') json
close(json_unit)
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
]
}
}
◆ json_up()
subroutine mod_json_writer::json_up |
( |
class(t_json), intent(inout) |
json | ) |
|
- Parameters
-
[in,out] | json | JSON container |