error: Unknown JSON type "NULL" in function "json.get

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

Post Reply
ziltmilt
Dragon
Posts: 331
Joined: Sun Apr 29, 2007 9:28 pm
Contact:

error: Unknown JSON type "NULL" in function "json.get

Post by ziltmilt »

I'm trying to build a real simple spell selection set of macros for my players, but in trying to return a list of eligible spells depending on the Class & Level passed to a UDF, I keep running into the error msg in the subject line.

Here's the body of the UDF:

Code: Select all

[h: Level = arg(0)]
[h: Class = arg(1)]
[h: spells = getLibProperty("Spells", "Lib:Utility")]
[h, foreach (spell, spells): SpellList = if(json.get(spell, "SpellLevel") == Level && upper(json.get(spell, "SpellType")) == upper(Class) , json.append(SpellList, spell), SpellList)]

[h: macro.return = SpellList]
Entries in Spells property are bracketed and look like this:

Code: Select all


{"SpellSource":"bfrpg","Spell":"Detect Magic","SpellType":"cleric","SpellLevel":1}


I must be doing something wrong, but for the life of me, I can't figure out what it could be. The calls to Json.Get look right. Does anyone see where I've goofed on this?

User avatar
aliasmask
RPTools Team
Posts: 9029
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: error: Unknown JSON type "NULL" in function "json.get

Post by aliasmask »

Sounds like empty data. I recommend spreading out the code to multiple lines to find the source.

After taking a close look, you don't have SpellList defined before the loop.

Code: Select all

[H: SpellList = "[]"]
Also, you have to be careful with reserved words like "Class". The MT parser may misinterpret it. I forget the exact circumstances where it blows up, so your use may be okay, but it's something to consider changing, like to className.

Post Reply

Return to “Macros”