json.contains: Difference between revisions
Jump to navigation
Jump to search
Verisimilar (talk | contribs) m (Macros:Functions:json.contains moved to json.contains) |
Verisimilar (talk | contribs) m (Updated with recent version changes.) |
||
Line 2: | Line 2: | ||
|name=json.contains | |name=json.contains | ||
|version=1.3b49 | |version=1.3b49 | ||
|description | |description= | ||
Returns | Returns {{true}} if the [[JSON Object]] contains the specified key, or if the [[JSON Array]] contains the specified value. | ||
|usage= | |usage= | ||
<source lang="mtmacro" line> | <source lang="mtmacro" line> | ||
json.contains(object, key) | |||
</source> | </source> | ||
<source lang="mtmacro" line> | |||
json.contains(array, value) | |||
</source> | |||
'''Parameters''' | |||
{{param|object|The [[JSON Object]] to test for the key.}} | |||
{{param|key|The key to check the object for.}} | |||
{{param|array|The [[JSON Array]] to test for the value.}} | |||
{{param|value|The value to check the array for.}} | |||
|examples= | |examples= | ||
Check if the [[JSON Object]] {{code|a}} contains the key {{code|"b"}}: | |||
<source lang="mtmacro" line> | |||
[h:a=json.fromStrProp("a=1;b=44;c=12")] | |||
[json.contains(a,"b")] | |||
</source> | |||
Returns {{true}} | |||
Check if the [[JSON Object]] {{code|a}} contains the key {{code|"z"}}: | |||
<source lang="mtmacro" line> | <source lang="mtmacro" line> | ||
[h:a=json.fromStrProp("a=1;b=44;c=12")] | |||
[json.contains(a,"z")] | |||
</source> | </source> | ||
Returns {{false}} | |||
Check if the [[JSON Array]] {{code|a}} contains the value {{code|"b"}}: | |||
<source lang="mtmacro" line> | |||
[h:a=json.fromList("1,b,3,d")] | |||
[json.contains(a,"b")] | |||
</source> | |||
Returns {{true}} | |||
|also= | |||
{{func|json.type}} | |||
|changes= | |||
{{change|1.3b51|Added ability for function to work with [[JSON Array]]s.}} | |||
}} | }} | ||
[[Category:JSON Function]] | [[Category:JSON Function]] |
Revision as of 05:31, 31 March 2009
json.contains() Function
• Introduced in version 1.3b49
Returns
true
(1
) if the JSON Object contains the specified key, or if the JSON Array contains the specified value.Usage
json.contains(object, key)
json.contains(array, value)
Parameters
object
- The JSON Object to test for the key.key
- The key to check the object for.array
- The JSON Array to test for the value.value
- The value to check the array for.
Examples
Check if the JSON Object
Returns
a
contains the key "b"
:
[h:a=json.fromStrProp("a=1;b=44;c=12")]
[json.contains(a,"b")]
Returns true
(1
)
Check if the JSON Object a
contains the key "z"
:
[h:a=json.fromStrProp("a=1;b=44;c=12")]
[json.contains(a,"z")]
Returns false
(0
)
Check if the JSON Array a
contains the value "b"
:
[h:a=json.fromList("1,b,3,d")]
[json.contains(a,"b")]
true
(1
)See Also
Version Changes
- 1.3b51 - Added ability for function to work with JSON Arrays.