json.length: Difference between revisions

From RPTools Wiki
Jump to navigation Jump to search
(New page: ==Function json.length== '''Introduced in MapTool 1.3b49''' Returns the number of fields in a Macros:json object or number of elements in a Macros:json array. ===Usage=== <...)
 
No edit summary
 
(7 intermediate revisions by 5 users not shown)
Line 1: Line 1:
==Function json.length==
{{MacroFunction
|name=json.length
|version=1.3b49
|description=
Returns the number of fields in a [[JSON Object|json object]] or number of elements in a [[JSON Array|json array]].


 
|usage=
 
<syntaxhighlight lang="mtmacro" line>
'''Introduced in MapTool 1.3b49'''
 
Returns the number of fields in a [[Macros:json object|json object]] or number of elements in a [[Macros:json array|json array]].
 
 
===Usage===
<source lang="mtmacro" line>
[h: len = json.length(jobj)]
[h: len = json.length(jobj)]
[h: len = json.length(jarr)]
[h: len = json.length(jarr)]
</source>
</syntaxhighlight>
 


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


Returns
Returns
  3
<pre>  3
   4
   4</pre>
}}
[[Category:JSON Function]]

Latest revision as of 17:40, 15 March 2023

json.length() Function

Introduced in version 1.3b49
Returns the number of fields in a json object or number of elements in a json array.

Usage

[h: len = json.length(jobj)]
[h: len = json.length(jarr)]

Example

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

Returns

  3
  4