json.remove: Difference between revisions

From RPTools Wiki
Jump to navigation Jump to search
(New page: ==Function json.remove== '''Introduced in MapTool 1.3b49''' Removes a field from a Macros:json object, or the value at the specified index from a json array. ...)
 
No edit summary
 
(7 intermediate revisions by 4 users not shown)
Line 1: Line 1:
==Function json.remove==
{{MacroFunction
|name=json.remove
|version=1.3b49
|description=
Removes a field from a [[JSON Object]], or the value at the specified index from a [[JSON Array]]. If the field is not present in the [[JSON Object]], it is returned unchanged. If the index does not exist in a [[JSON Array]], a java.lang.IndexOutOfBoundsException is raised.


 
|usage=
 
<syntaxhighlight lang="mtmacro" line>
'''Introduced in MapTool 1.3b49'''
Removes a field from a [[Macros:json object|json object]], or the value at the specified index from a [[Macros:json array|json array]].
 
===Usage===
<source lang="mtmacro" line>
[h: jarr = json.remove(jarr, index)]
[h: jarr = json.remove(jarr, index)]
[h: jarr = json.remove(jobj, key)]
[h: jarr = json.remove(jobj, key)]
</source>
</syntaxhighlight>
 


===Examples===
|examples=
<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
   [h:a=json.fromStrProp("a=1;b=44;c=12")] [r:json.remove(a, "c")]
   [h:a=json.fromStrProp("a=1;b=44;c=12")] [r:json.remove(a, "c")]
   [h:a=json.fromList("a,1,g,4")][r:json.remove(a,3)]
   [h:a=json.fromList("a,1,g,4")][r:json.remove(a,3)]
</source>
</syntaxhighlight>


Returns
Returns
   {"a":1,"b":44}
   {"a":1,"b":44}
   ["a",1,"g"]
   ["a",1,"g"]
}}
[[Category:JSON Function]]

Latest revision as of 23:59, 15 March 2023

json.remove() Function

Introduced in version 1.3b49
Removes a field from a JSON Object, or the value at the specified index from a JSON Array. If the field is not present in the JSON Object, it is returned unchanged. If the index does not exist in a JSON Array, a java.lang.IndexOutOfBoundsException is raised.

Usage

[h: jarr = json.remove(jarr, index)]
[h: jarr = json.remove(jobj, key)]

Examples

  [h:a=json.fromStrProp("a=1;b=44;c=12")] [r:json.remove(a, "c")]
  [h:a=json.fromList("a,1,g,4")][r:json.remove(a,3)]

Returns

 {"a":1,"b":44}
["a",1,"g"]