Note: The JSON specification does not define integer or float types, but only a
number type. Therefore, converting a Variant to JSON text will convert all numerical values to
float types.
Note: If
full_precision is
true, when stringifying floats, the unreliable digits are stringified in addition to the reliable digits to guarantee exact decoding.
The
indent parameter controls if and how something is indented; its contents will be used where there should be an indent in the output. Even spaces like
" " will work.
\t and
\n can also be used for a tab indent, or to make a newline for each indent respectively.
Warning: Non-finite numbers are not supported in JSON. Any occurrences of [constant @GDScript.INF] will be replaced with
1e99999, and negative [constant @GDScript.INF] will be replaced with
-1e99999, but they will be interpreted correctly as infinity by most JSON parsers. [constant @GDScript.NAN] will be replaced with
null, and it will not be interpreted as NaN in JSON parsers. If you expect non-finite numbers, consider passing your data through
from_native first.
Example output:
## JSON.stringify(my_dictionary)
{"name":"my_dictionary","version":"1.0.0","entities":[{"name":"entity_0","value":"value_0"},{"name":"entity_1","value":"value_1"}]}
## JSON.stringify(my_dictionary, "\t")
{
"name": "my_dictionary",
"version": "1.0.0",
"entities": [
{
"name": "entity_0",
"value": "value_0"
},
{
"name": "entity_1",
"value": "value_1"
}
]
}
## JSON.stringify(my_dictionary, "...")
{
..."name": "my_dictionary",
..."version": "1.0.0",
..."entities": [
......{
........."name": "entity_0",
........."value": "value_0"
......},
......{
........."name": "entity_1",
........."value": "value_1"
......}
...]
}