JSON serializer implementation.
This module provides procedures and types for serializing TOML Fortran data structures to JSON format.
The json_ser_config type allows customizing the serialization output:
indent - String used for indentation (e.g., " " for 2 spaces)literal_nan - Write NaN as literal instead of stringliteral_inf - Write Inf as literal instead of stringliteral_datetime - Write datetime as literal instead of stringuse jonquil, only : json_object, json_dumps, json_ser_config, &
& new_object, set_value
type(json_object) :: obj
type(json_ser_config) :: config
character(:), allocatable :: str
call new_object(obj)
call set_value(obj, "key", "value")
config%indent = " " ! Pretty print with 2-space indent
call json_dumps(obj, str, config=config)
print '(a)', str
Write string representation of JSON value to a file
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(toml_value), | intent(inout) | :: | val |
TOML value to visit |
||
| character(len=*), | intent(in) | :: | filename |
File name to write to |
||
| type(toml_error), | intent(out), | allocatable | :: | error |
Error handling |
|
| type(json_ser_config), | intent(in), | optional | :: | config |
Configuration for serializer |
Write string representation of JSON value to a connected formatted unit
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(toml_value), | intent(inout) | :: | val |
TOML value to visit |
||
| integer, | intent(in) | :: | io |
Formatted unit to write to |
||
| type(toml_error), | intent(out), | allocatable | :: | error |
Error handling |
|
| type(json_ser_config), | intent(in), | optional | :: | config |
Configuration for serializer |
Create a string representing the JSON value
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(toml_value), | intent(inout) | :: | val |
TOML value to visit |
||
| character(len=:), | intent(out), | allocatable | :: | string |
Formatted unit to write to |
|
| type(toml_error), | intent(out), | allocatable | :: | error |
Error handling |
|
| type(json_ser_config), | intent(in), | optional | :: | config |
Configuration for serializer |
Configuration for JSON serializer
| Type | Visibility | Attributes | Name | Initial | |||
|---|---|---|---|---|---|---|---|
| character(len=:), | public, | allocatable | :: | indent |
Indentation |
||
| logical, | public | :: | literal_datetime | = | .false. |
Write literal datetime |
|
| logical, | public | :: | literal_inf | = | .false. |
Write literal Inf |
|
| logical, | public | :: | literal_nan | = | .false. |
Write literal NaN |
Serializer to produduce a JSON document from a TOML datastructure
| Type | Visibility | Attributes | Name | Initial | |||
|---|---|---|---|---|---|---|---|
| type(json_ser_config), | public | :: | config | = | json_ser_config() |
Configuration for serializer |
|
| integer, | public | :: | depth | = | 0 |
Current depth in the tree |
|
| character(len=:), | public, | allocatable | :: | output |
Output string |
| procedure, public :: visit | Visit a TOML value |
Serialize a JSON value to a string and return it.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(toml_value), | intent(inout) | :: | val |
TOML value to visit |
||
| type(json_ser_config), | intent(in), | optional | :: | config |
Configuration for serializer |
Serialized JSON value