json.merge: Difference between revisions
Jump to navigation
Jump to search
m (Tweaking page layout and typography) |
No edit summary |
||
(3 intermediate revisions by 2 users not shown) | |||
Line 10: | Line 10: | ||
|usage= | |usage= | ||
< | <syntaxhighlight lang="mtmacro" line> | ||
json.merge(array, array, ...) | json.merge(array, array, ...) | ||
</ | </syntaxhighlight> | ||
< | <syntaxhighlight lang="mtmacro" line> | ||
json.merge(object, object, ...) | json.merge(object, object, ...) | ||
</ | </syntaxhighlight> | ||
'''Parameters''' | '''Parameters''' | ||
{{param|array|A [[JSON Array]].}} | {{param|array|A [[JSON Array]].}} | ||
Line 22: | Line 22: | ||
|examples= | |examples= | ||
Merge three [[JSON Array]]s: | Merge three [[JSON Array]]s: | ||
< | <syntaxhighlight lang="mtmacro" line> | ||
[r: json.merge("[1,2]", "[3,4]", "[1,2]")] | [r: json.merge("[1,2]", "[3,4]", "[1,2]")] | ||
</ | </syntaxhighlight> | ||
Returns: {{code|[1,2,3,4,1,2]}} | Returns: {{code|[1,2,3,4,1,2]}} | ||
Merge two [[JSON Object]]s with no matching keys: | Merge two [[JSON Object]]s with no matching keys: | ||
< | <syntaxhighlight lang="mtmacro" line> | ||
[r: json.merge("{a:1, b:2}", "{c:10, d:7}")] | [r: json.merge("{a:1, b:2}", "{c:10, d:7}")] | ||
</ | </syntaxhighlight> | ||
Returns: {{code|{"a":1,"b":2,"c":10,"d":7} }} | Returns: {{code|{"a":1,"b":2,"c":10,"d":7} }} | ||
Merge three [[JSON Object]]s with a matching key, {{code|a}}: | Merge three [[JSON Object]]s with a matching key, {{code|a}}: | ||
< | <syntaxhighlight lang="mtmacro" line> | ||
[r: json.merge("{a:1, b:2}", "{c:10, d:7}", "{a:11, z:7}")] | [r: json.merge("{a:1, b:2}", "{c:10, d:7}", "{a:11, z:7}")] | ||
</ | </syntaxhighlight> | ||
Returns: {{code|{"a":11,"b":2,"c":10,"d":7,"z":7} }} | Returns: {{code|{"a":11,"b":2,"c":10,"d":7,"z":7} }} | ||
Latest revision as of 23:59, 15 March 2023
json.merge() Function
• Introduced in version 1.3b53
Merges multiple JSON Arrays or JSON Objects.
For JSON Arrays the value returned is that of all the JSON Arrays concatenated together.
For JSON Objects the value returned is a JSON Object with all of the keys from all of the JSON Objects set, if any key is specified in more than one JSON Object then the value for the last specified JSON Object is used.Usage
json.merge(array, array, ...)
json.merge(object, object, ...)
Parameters
array
- A JSON Array.object
- A JSON Object.
Examples
Merge three JSON Arrays:
Returns:
[r: json.merge("[1,2]", "[3,4]", "[1,2]")]
Returns: [1,2,3,4,1,2]
Merge two JSON Objects with no matching keys:
[r: json.merge("{a:1, b:2}", "{c:10, d:7}")]
Returns: {"a":1,"b":2,"c":10,"d":7}
Merge three JSON Objects with a matching key, a
:
[r: json.merge("{a:1, b:2}", "{c:10, d:7}", "{a:11, z:7}")]
{"a":11,"b":2,"c":10,"d":7,"z":7}
See Also
Version Changes
- 1.3b54 - Fixed bug which allows
json.merge()
to work correctly with JSON Objects.