json.fields: Difference between revisions

From RPTools Wiki
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...)
 
m (Applied Template:MacroFunction)
Line 1: Line 1:
==Function json.fields==
{{MacroFunction
 
|name=json.fields
 
|version=1.3b49
 
|description=
'''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 depends on the delimiter parameter.  
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.  
* If the delimiter is not specified then a [[Macros:string list|string list]] is returned with the default value of ',' is used.
* If the delimiter is not specified then a [[Macros:string list|string list]] is returned with the default value of ',' is used.
Line 10: Line 8:
* Otherwise a [[Macros:string list|string list]] is returned with the delimiter passed in.
* Otherwise a [[Macros:string list|string list]] is returned with the delimiter passed in.


 
|usage=
 
===Usage===
<source lang="mtmacro" line>
<source lang="mtmacro" line>
[h: strList = json.fields(jobj)]
[h: strList = json.fields(jobj)]
Line 19: Line 15:
</source>
</source>


 
|example=
===Examples===
<source lang="mtmacro" line>
<source lang="mtmacro" line>
   [h:a=json.fromStrProp("a=1;b=44;c=12")] [r:json.fields(a)]
   [h:a=json.fromStrProp("a=1;b=44;c=12")] [r:json.fields(a)]
Line 31: Line 26:
   0,1,2,3  
   0,1,2,3  
   ["a","c","b"]
   ["a","c","b"]
}}
[[Category:JSON Function]]

Revision as of 02:03, 9 March 2009

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.
  • If the delimiter is not specified then a string list is returned with the default value of ',' is used.
  • If the delimiter "json" then a json array is returned.
  • Otherwise a string list is returned with the delimiter passed in.

Usage

[h: strList = json.fields(jobj)]
[h: strList = json.fields(jobj, delim)]
[h: jobj = json.fields(jobj, 'json')]

Example

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

Returns

 a,c,b
 0,1,2,3 
["a","c","b"]