json.append: Difference between revisions

From RPTools Wiki
Jump to navigation Jump to search
m (Conversion script moved page Json.append to json.append: Converting page titles to lowercase)
No edit summary
Line 6: Line 6:


|usage=
|usage=
<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
[h: jarr = json.append(jarr, value, ...)]
[h: jarr = json.append(jarr, value, ...)]
</source>
</syntaxhighlight>


|example=
|example=
Create a JSON array from a string list and then append an additional value.
Create a JSON array from a string list and then append an additional value.
<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
[h:a=json.fromList("a,1,g,4")]
[h:a=json.fromList("a,1,g,4")]
[r: json.append(a, 55)]
[r: json.append(a, 55)]
</source>
</syntaxhighlight>
Returns
Returns
<source lang="javascript">
<syntaxhighlight lang="javascript">
["a",1,"g",4,55]
["a",1,"g",4,55]
</source>
</syntaxhighlight>


Create a JSON array directly with append.
Create a JSON array directly with append.
<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
[r: json.append("", 1, 5, 8, 33)]
[r: json.append("", 1, 5, 8, 33)]
</source>
</syntaxhighlight>


Returns
Returns
<source lang="javascript">
<syntaxhighlight lang="javascript">
[1,5,8,33]
[1,5,8,33]
</source>
</syntaxhighlight>


}}
}}
[[Category:JSON Function]]
[[Category:JSON Function]]

Revision as of 18:43, 15 March 2023

json.append() Function

Introduced in version 1.3b49
Appends values to the end of a JSON Array. An empty string ("") can be used to represent an empty JSON Array to append the values to.

Usage

[h: jarr = json.append(jarr, value, ...)]

Example

Create a JSON array from a string list and then append an additional value.
[h:a=json.fromList("a,1,g,4")]
[r: json.append(a, 55)]

Returns

["a",1,"g",4,55]

Create a JSON array directly with append.

[r: json.append("", 1, 5, 8, 33)]

Returns

[1,5,8,33]