json.unique

From RPTools Wiki
Revision as of 14:04, 29 March 2009 by Craig (talk | contribs) (New page: {{MacroFunction |name=json.unique |version=1.3b53 |description= Returns a JSON Array with each value that occurs in the source JSON Array occurring only once. The relative order o...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

json.unique() Function

Introduced in version 1.3b53
Returns a JSON Array with each value that occurs in the source JSON Array occurring only once. The relative order of the values in the array may not be preserved.

Usage

[h: jarr = json.unique(jarr)]


Parameters

Examples

Lets say you have a JSON Array that contains the following Token names.

["Hero", "Dragon"] and you use getPCNames() to return the names of the PC Tokens, you could use the following code to generate a JSON Array that contains the values in both JSON Arrays with no value present more than once.

[h: names1 = '["Hero", "Dragon"]']
[h: names2 = getNPCNames()]
[h: names = json.merge(names1, names2)]
[r: json.unique(names)]

If getPCName() returns ["Hero", "Sidekick", "Policeman"] then the result of the above code will be

["Policeman","Sidekick","Hero","Dragon"]