minecraft.wiki-mirror/wiki_backup/JSON.txt
2024-12-24 06:17:34 -05:00

91 lines
3.8 KiB
Text
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

'''JavaScript Object Notation''' ('''JSON''') is a lightweight data-interchange format.<ref>https://www.json.org</ref> It consists of key-value pairs and arrays values, and it is used for storing and transmitting data in ''Minecraft''.
== Occurences ==
In ''Minecraft'', JSON format is used to store the following data:
* [[Text]] in [[written book]]s, [[sign]]s, custom names and the {{cmd|tellraw}}, {{cmd|title}}, {{cmd|bossbar}}, {{cmd|scoreboard}} and {{cmd|team}} commands.{{only|java}}
* The <code>pack.mcmeta</code> file that describes a {{el|je}} [[resource pack]] and [[data pack]].
* The <code>manifest.json</code> file that describes a {{el|be}} [[add-on]].
* Files in a resource pack that define [[model]]s, [[sounds.json|sound events]], UI, etc.{{only|bedrock}}
* Files in a behavior pack that define [https://docs.microsoft.com/en-us/minecraft/creator/reference/content/entityreference/ entity behaviors], [https://docs.microsoft.com/en-us/minecraft/creator/reference/content/blockreference/ block behaviors], item behaviors, etc.{{only|bedrock}}
* [[Advancements]] and [[statistics]] (as <code>.minecraft/saves/*/data/stats/*.json</code>)
* The profile data for the [[launcher]] (as [[launcher_profiles.json]])
* Information about downloaded [[version]]s (as [[version.json]])
* Files in a data pack that define [[advancements]], [[loot table]]s, [[tags]], [[recipes]], [[Custom dimension|dimensions]], [[Custom dimension|dimension types]] and [[predicates]].{{only|java}}
== Syntax ==
=== Data types ===
A JSON file must contain a single JSON value, which can use any of the following five data types: string, number, object, array, and boolean. JSON files can be contained in a single line, however it is often useful to use indentation and line breaks to make a long JSON file more readable.
==== String ====
A {{w|String (computer science)|string}} is delimited by quotes and can contain any combination of characters. Some special characters need to be escaped; this is done with a back slash (<code>\</code>).
* {{cd|"foo"}}
* {{cd|"Hello, world"}}
* {{cd|"An escaped \" quote within a string"}}
==== Number ====
A number is defined by entering in any number. Numbers can be non-whole, as indicated with a period, and can use exponents with <code>e</code>.
* {{cd|2}}
* {{cd|-0.5}}
* {{cd|3e6}} (=3×10<sup>6</sup>)
==== Object ====
An {{w|Object (computer science)|object}}, also referred to as a compound, is delimited by opening and closing curly brackets and contains key/value pairs. Pairs are separated with commas, keys and associated values are separated with colons. Each contained key needs to have a name that is unique within the object. A value can be of any data type as well (including another object).
<syntaxhighlight lang="json" line="1">
{
"Bob": {
"ID": 1234,
"lastName": "Ramsay"
},
"Alice": {
"ID": 2345,
"lastName": "Berg"
}
}
</syntaxhighlight>
==== Array ====
{{w|Array (data type)|Array}}s are delimited by opening and closing square brackets and can contain values of any data type, separated by commas. Unlike lists in NBT, values in a JSON array can use different data types.
<syntaxhighlight lang="json">
["Bob", "Alice", "Carlos", "Eve"]
</syntaxhighlight>
==== Boolean ====
A {{w|Boolean data type|boolean}} can be either <code>true</code> or <code>false</code>.
<syntaxhighlight lang="json" line="1">
{
"Steve": {
"isAlive": true
},
"Alex": {
"isAlive": false
}
}
</syntaxhighlight>
== See also ==
* https://en.wikipedia.org/wiki/JSON
==References==
{{Reflist}}
== Navigation ==
{{Navbox Java Edition technical|general}}
{{Navbox Bedrock Edition}}
[[Category:Development]]
[[de:JSON]]
[[es:JSON]]
[[fr:JSON]]
[[ja:JSON]]
[[lzh:JSON]]
[[pt:JSON]]
[[ru:Команды консоли#JSON-текст]]
[[th:JSON]]
[[uk:JSON]]
[[zh:JSON]]