A database of properties: can it be done? Suggestions on the approach?

Discuss macro implementations, ask for macro help (to share your creations, see User Creations, probably either Campaign Frameworks or Drop-in Resources).

Moderators: dorpond, trevor, Azhrei, giliath, jay, Mr.Ice

User avatar
aliasmask
RPTools Team
Posts: 9080
Joined: Tue Nov 10, 2009 6:11 pm
Location: California

Re: A database of properties: can it be done? Suggestions on the approach?

Post by aliasmask »

Wiki: json.merge() if you want to merge arrays.

AstralWanderer
Cave Troll
Posts: 31
Joined: Sat May 11, 2019 8:41 am

Re: A database of properties: can it be done? Suggestions on the approach?

Post by AstralWanderer »

To get around a number of problems, I turned to a variation that doesn't use json.path.read():

Code: Select all

[h: filteredList = ""]
[h: inputValueIsNumber = isNumber(arg(2))]
[h: Arg2 = arg(2)]
[h, if(!inputValueIsNumber): Arg2 = "(?<![a-zA-Z])(" + arg(2) + ")(?![a-zA-Z])"]
[h, foreach(item,arg(0)), code:
{
	[h, if(inputValueIsNumber): Matching = matches(json.get(item, arg(1)), Arg2); Matching = getFindCount(strfind(json.get(item, arg(1)), Arg2))]
	[h, if(Matching): filteredList = json.append(filteredList, item)]
}]

[h: macro.return = filteredList]
This sprang from the json.merge() suggestion. This way I always get arrays and can merge them no problem, step after step, up to the final filtered list.

Post Reply

Return to “Macros”