Skip to content

armgit / godot

Public Imported from GitHub
0

Godot Engine – Multi-platform 2D and 3D game engine

Improve `JSON.stringify()` documentation

Hugo Locurcioe57e643549f9
diff --git a/doc/classes/JSON.xml b/doc/classes/JSON.xml
index eae3c54f1db..6e7770b75f8 100644
--- a/doc/classes/JSON.xml
+++ b/doc/classes/JSON.xml
@@ -95,16 +95,16 @@
<param index="3" name="full_precision" type="bool" default="false" />
<description>
Converts a [Variant] var to JSON text and returns the result. Useful for serializing data to store or send over the network.
+ If [param sort_keys] is [code]true[/code], the keys of any [Dictionary]s are sorted alphabetically when converting to JSON. If [param full_precision] is [code]true[/code], when stringifying floats, the unreliable digits are stringified in addition to the reliable digits to guarantee exact decoding.
[b]Note:[/b] The JSON specification does not define integer or float types, but only a [i]number[/i] type. Therefore, converting a Variant to JSON text will convert all numerical values to [float] types.
- [b]Note:[/b] If [param full_precision] is [code]true[/code], when stringifying floats, the unreliable digits are stringified in addition to the reliable digits to guarantee exact decoding.
- The [param 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 [code]" "[/code] will work. [code]\t[/code] and [code]\n[/code] can also be used for a tab indent, or to make a newline for each indent respectively.
+ The [param 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 [code]" "[/code] will work. [code]\t[/code] and [code]\n[/code] can also be used for a tab indent, or to make a newline for each indent respectively. If set to an empty string, the JSON will be on a single line with no spacing, which allows for smaller file sizes.
[b]Warning:[/b] Non-finite numbers are not supported in JSON. Any occurrences of [constant @GDScript.INF] will be replaced with [code]1e99999[/code], and negative [constant @GDScript.INF] will be replaced with [code]-1e99999[/code], but they will be interpreted correctly as infinity by most JSON parsers. [constant @GDScript.NAN] will be replaced with [code]null[/code], and it will not be interpreted as NaN in JSON parsers. If you expect non-finite numbers, consider passing your data through [method from_native] first.
[b]Example output:[/b]
[codeblock]
- ## JSON.stringify(my_dictionary)
+ ## JSON.stringify(my_dictionary, "", false)
{"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")
+ ## JSON.stringify(my_dictionary, "\t", false)
{
"name": "my_dictionary",
"version": "1.0.0",
@@ -120,7 +120,7 @@
]
}
- ## JSON.stringify(my_dictionary, "...")
+ ## JSON.stringify(my_dictionary, "...", false)
{
..."name": "my_dictionary",
..."version": "1.0.0",