json.append: Difference between revisions

From RPTools Wiki
Jump to navigation Jump to search
(New page: ==Function json.set== '''Introduced in MapTool 1.3b49''' Appends values to the end of a json array. An empty string ("") can be used to represent an empty [[Macros...)
 
No edit summary
 
(9 intermediate revisions by 5 users not shown)
Line 1: Line 1:
==Function json.set==
{{MacroFunction
|name=json.append
|version=1.3b49
|description=
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=
<syntaxhighlight lang="mtmacro" line>
[h: jarr = json.append(jarr, value, ...)]
</syntaxhighlight>


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


'''Introduced in MapTool 1.3b49'''
Create a JSON array directly with append.
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.
<syntaxhighlight lang="mtmacro" line>
[r: json.append("", 1, 5, 8, 33)]
</syntaxhighlight>


===Usage===
Returns
<source lang="mtmacro" line>
<syntaxhighlight lang="javascript">
[h: jarr = json.get(jarr, value, ...)]
[1,5,8,33]
</source>
</syntaxhighlight>


 
}}
===Examples===
[[Category:JSON Function]]
<source lang="mtmacro" line>
  [h:a=json.fromList("a,1,g,4")][r: json.append(a, 55)]
  [r: json.append("", 1, 5, 8, 33)]
</source>
 
Returns
  ["a",1,"g",4,55]
  [1,5,8,33]

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]