json.append: Difference between revisions

From RPTools Wiki
Jump to navigation Jump to search
(Applied Template:MacroFunction)
No edit summary
 
(6 intermediate revisions by 4 users not shown)
Line 3: Line 3:
|version=1.3b49
|version=1.3b49
|description=
|description=
Appends values to the end of a [[Macros:json array|json array]]. An empty string ("") can be used to represent an empty [[Macros:json array|json array]] to append the values to.
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=
|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=
<source lang="mtmacro" line>
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)]
<syntaxhighlight lang="mtmacro" line>
  [r: json.append("", 1, 5, 8, 33)]
[h:a=json.fromList("a,1,g,4")]
</source>
[r: json.append(a, 55)]
</syntaxhighlight>
Returns
<syntaxhighlight lang="javascript">
["a",1,"g",4,55]
</syntaxhighlight>
 
Create a JSON array directly with append.
<syntaxhighlight lang="mtmacro" line>
[r: json.append("", 1, 5, 8, 33)]
</syntaxhighlight>


Returns
Returns
  ["a",1,"g",4,55]
<syntaxhighlight lang="javascript">
  [1,5,8,33]
[1,5,8,33]
</syntaxhighlight>
 
}}
}}
[[Category:JSON Function]]
[[Category:JSON Function]]

Latest revision as of 23:59, 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]