json.fields: Difference between revisions
Jump to navigation
Jump to search
(New page: ==Function json.fields== '''Introduced in MapTool 1.3b49''' Returns the fields (keys) for a json object or the indexes for a json array as a string list. The type of the value returned...) |
No edit summary |
||
(10 intermediate revisions by 6 users not shown) | |||
Line 1: | Line 1: | ||
= | {{MacroFunction | ||
|name=json.fields | |||
|version=1.3b49 | |||
|description= | |||
Returns the fields (keys) for a [[JSON Object]] or the indexes for a [[JSON Array]] as a string list. The type of the value returned depends on the delimiter parameter. | |||
<u>Note</u>: Because [[JSON Object]]s are unordered, ''json.fields'' will not reflect the order they were set in. | |||
|usage= | |||
<syntaxhighlight lang="mtmacro" line> | |||
json.fields(jobj) | |||
</syntaxhighlight> | |||
<syntaxhighlight lang="mtmacro" line> | |||
json.fields(jobj, delim) | |||
</syntaxhighlight> | |||
''' | '''Parameters''' | ||
* {{code|delim}} = | |||
** {{code|unspecified}}: a standard [[Macros:string list|string list]] is returned, with its default {{code|","}} delimiter. | |||
** {{code|"json"}}: a [[JSON Array]] is returned. | |||
** {{code|"x"}}: a [[Macros:string list|string list]] is returned with {{code|"x"}} used as a delimiter. | |||
|example= | |||
<syntaxhighlight lang="mtmacro" line> | |||
[h: a=json.fromStrProp("a=1;b=44;c=12")] | |||
[r: json.fields(a)] | |||
</syntaxhighlight> | |||
Returns | |||
a,b,c | |||
<syntaxhighlight lang="mtmacro" line> | |||
[h: a=json.fromList("a,1,g,4")] | |||
[r: json.fields(a,";")] | |||
</syntaxhighlight> | |||
Returns | |||
0;1;2;3 | |||
<syntaxhighlight lang="mtmacro" line> | |||
[h: a=json.fromStrProp("a=1;b=44;c=12")] | |||
[r: json.fields(a, "json")] | |||
</syntaxhighlight> | |||
Returns | Returns | ||
["a","b","c"] | |||
}} | |||
["a"," | [[Category:JSON Function]] |
Latest revision as of 23:59, 15 March 2023
json.fields() Function
• Introduced in version 1.3b49
Returns the fields (keys) for a JSON Object or the indexes for a JSON Array as a string list. The type of the value returned depends on the delimiter parameter.
Note: Because JSON Objects are unordered, json.fields will not reflect the order they were set in.
Usage
json.fields(jobj)
json.fields(jobj, delim)
Parameters
delim
=unspecified
: a standard string list is returned, with its default","
delimiter."json"
: a JSON Array is returned."x"
: a string list is returned with"x"
used as a delimiter.
Example
[h: a=json.fromStrProp("a=1;b=44;c=12")]
[r: json.fields(a)]
Returns
a,b,c
[h: a=json.fromList("a,1,g,4")]
[r: json.fields(a,";")]
Returns
0;1;2;3
[h: a=json.fromStrProp("a=1;b=44;c=12")]
[r: json.fields(a, "json")]
Returns
["a","b","c"]