Scripting: JSON – Arma Reforger
Lou Montana (talk | contribs) m (Text replacement - "<syntaxhighlight lang="c#">" to "<enforce>") |
Lou Montana (talk | contribs) m (Text replacement - "</syntaxhighlight>" to "</enforce>") |
||
Line 17: | Line 17: | ||
{ | { | ||
} | } | ||
</ | </enforce> | ||
A property is defined with its name on the left of the colon, and its value on the right. '''Properties and strings''' are defined by '''double-quotes''' {{hl|"}}.<br> | A property is defined with its name on the left of the colon, and its value on the right. '''Properties and strings''' are defined by '''double-quotes''' {{hl|"}}.<br> | ||
Line 28: | Line 28: | ||
"property": 42 | "property": 42 | ||
} | } | ||
</ | </enforce> | ||
<syntaxhighlight lang="json"> | <syntaxhighlight lang="json"> | ||
{ | { | ||
Line 34: | Line 34: | ||
"property2": "fourty-two" | "property2": "fourty-two" | ||
} | } | ||
</ | </enforce> | ||
Spacing does not matter outside of the quotes. | Spacing does not matter outside of the quotes. | ||
Line 42: | Line 42: | ||
"property2": 42 | "property2": 42 | ||
} | } | ||
</ | </enforce> | ||
is identical to | is identical to | ||
<syntaxhighlight lang="json"> | <syntaxhighlight lang="json"> | ||
{"property1":"name","property2":42} | {"property1":"name","property2":42} | ||
</ | </enforce> | ||
but for obvious readability reasons, tabs and spaces are welcome. | but for obvious readability reasons, tabs and spaces are welcome. | ||
Line 57: | Line 57: | ||
"boolean2": false | "boolean2": false | ||
} | } | ||
</ | </enforce> | ||
=== Number === | === Number === | ||
Line 69: | Line 69: | ||
"number4": 10e10 | "number4": 10e10 | ||
} | } | ||
</ | </enforce> | ||
=== String === | === String === | ||
Line 91: | Line 91: | ||
"string2": "Is \"this\" a string?\tYes, Sir\u0021" | "string2": "Is \"this\" a string?\tYes, Sir\u0021" | ||
} | } | ||
</ | </enforce> | ||
=== Object === | === Object === | ||
Line 101: | Line 101: | ||
} | } | ||
} | } | ||
</ | </enforce> | ||
The null value is covered. | The null value is covered. | ||
Line 108: | Line 108: | ||
"object1": null | "object1": null | ||
} | } | ||
</ | </enforce> | ||
=== Array === | === Array === | ||
Line 129: | Line 129: | ||
] | ] | ||
} | } | ||
</ | </enforce> | ||
Line 153: | Line 153: | ||
}; | }; | ||
} | } | ||
</ | </enforce> | ||
Line 185: | Line 185: | ||
} | } | ||
} | } | ||
</ | </enforce> | ||
Revision as of 19:18, 30 July 2022
JSON Format
JSON stands for JavaScript Object Notation. It is a way to present data in a simple form.
The parent class is always an object (the O from JSON). <syntaxhighlight lang="json"> { } </enforce>
A property is defined with its name on the left of the colon, and its value on the right. Properties and strings are defined by double-quotes ".
If another property follows, a comma is required. If no other property follows, there must be no comma.
<syntaxhighlight lang="json"> { "property": 42 } </enforce> <syntaxhighlight lang="json"> { "property1": 41, "property2": "fourty-two" } </enforce>
Spacing does not matter outside of the quotes. <syntaxhighlight lang="json"> { "property1": "name", "property2": 42 } </enforce> is identical to <syntaxhighlight lang="json"> {"property1":"name","property2":42} </enforce> but for obvious readability reasons, tabs and spaces are welcome.
Boolean
A boolean can be either true or false and nothing else. <syntaxhighlight lang="json"> { "boolean1": true, "boolean2": false } </enforce>
Number
A number can be either an integer or a float. There are no quotes around it. It cannot start with a period .. Scientific notations are accepted. <syntaxhighlight lang="json"> { "number1": 42, "number2": 4.2, "number3": -33, "number4": 10e10 } </enforce>
String
Line returns cannot happen in JSON strings. The following character escape sequences are accepted:
\b \f \r \n \t \" \ \ - \
/ \u#### - see Unicode chars
<syntaxhighlight lang="json"> { "string1": "This is a string", "string2": "Is \"this\" a string?\tYes, Sir\u0021" } </enforce>
Object
<syntaxhighlight lang="json"> { "object1": { "property1": "sub-object" } } </enforce>
The null value is covered. <syntaxhighlight lang="json"> { "object1": null } </enforce>
Array
An array can contain anything: direct values, or other objects with named properties. <syntaxhighlight lang="json"> { "array1": [ 4, 5, 6 ], "array2": ["This", "is", "Sparta!"], "array3": [ { "name": "object's name", "value": 33 }, { "name": "another object, inlined", "value": 42 } ] } </enforce>
Hydration
- Properties must be named the same in JSON and in the Enforce Script object. They are case-sensitive!
- A missing property will not fail the JSON hydration.
Example
JSON Structure
MainClass.json <syntaxhighlight lang="json"> { "m_sMessage": "Hello Message", "m_subObject": { "integerValue": 1, "booleanValue": true }; } </enforce>
Script Usage