json.get: Difference between revisions
Jump to navigation
Jump to search
Verisimilar (talk | contribs) m (Macros:Functions:json.get moved to json.get) |
Verisimilar (talk | contribs) No edit summary |
||
Line 1: | Line 1: | ||
{{stub|Examples for the new functionality.}} | |||
{{MacroFunction | {{MacroFunction | ||
|name=json.get | |name=json.get | ||
|version=1.3b49 | |version=1.3b49 | ||
|description | |description= | ||
Returns the value in a [[ | Returns the value in a [[JSON array]] at the specified index, returns a slice of a [[JSON array]] from the specified indexes, or returns the value from [[JSON object]] for the specified key. | ||
|usage= | |usage= | ||
<source lang="mtmacro" line> | <source lang="mtmacro" line> | ||
json.get(array, index) | |||
</source> | </source> | ||
<source lang="mtmacro" line> | |||
json.get(array, start, end) | |||
</source> | |||
<source lang="mtmacro" line> | |||
json.get(object, key, key, ...) | |||
</source> | |||
'''Parameters''' | |||
{{param|array|The JSON array to retrieve the element from.}} | |||
{{param|index|The numerical index of the element you want returned.}} | |||
{{param|start|The starting index of the element you wish the slice to begin at.}} | |||
{{param|end|The ending index of the element you wish the slice to end at.}} | |||
{{param|object|The JSON object to retrieve the element from.}} | |||
{{param|key|The name of a field that should be returned. This parameter can exist more than once, if it does then a JSON object is returned with all the specified elements.}} | |||
Negative numbers can be used as the offsets from the end of the array, {{code|-1}} is the last element in the array, {{code|-2}} is the second to last, and so on. If the {{code|end}} index is smaller than the {{code|start}} index then the array slice is returned in reverse. | |||
|example= | |example= | ||
Line 20: | Line 35: | ||
44 | 44 | ||
44 | 44 | ||
|changes= | |||
{{change|1.3b51|Added ability to return JSON array slices.}} | |||
{{change|1.3b51|Added ability to return JSON objects of select fields from other JSON objects.}} | |||
}} | }} | ||
[[Category:JSON Function]] | [[Category:JSON Function]] |
Revision as of 00:41, 23 March 2009
This article is a stub, you can help the RPTools Wiki project by contributing content to expand this article.
This article needs: Examples for the new functionality.
json.get() Function
• Introduced in version 1.3b49
Returns the value in a JSON array at the specified index, returns a slice of a JSON array from the specified indexes, or returns the value from JSON object for the specified key.
Usage
json.get(array, index)
json.get(array, start, end)
json.get(object, key, key, ...)
Parameters
array
- The JSON array to retrieve the element from.index
- The numerical index of the element you want returned.start
- The starting index of the element you wish the slice to begin at.end
- The ending index of the element you wish the slice to end at.object
- The JSON object to retrieve the element from.key
- The name of a field that should be returned. This parameter can exist more than once, if it does then a JSON object is returned with all the specified elements.
Negative numbers can be used as the offsets from the end of the array, -1
is the last element in the array, -2
is the second to last, and so on. If the end
index is smaller than the start
index then the array slice is returned in reverse.
Example
[h:a=json.fromStrProp("a=1;b=44;c=12")] [json.get(a,"b")]
[h:a=json.fromList("1,44,12")] [json.get(a,1)]
Returns
4444
Version Changes
- 1.3b51 - Added ability to return JSON array slices.
- 1.3b51 - Added ability to return JSON objects of select fields from other JSON objects.