Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
Create a free account

JSON Import

November 05 (10 years ago)
I saw the API script to import XML files generated by HeroLab into the Pathfinder character sheet. That's an excellent bit of work. However, for my purposes, the PF character sheet is way overkill. I'm playing a tabletop game, using roll20 locally (each player has a laptop), but I don't want to automate everything, just some basic rolls.

I got the great idea to take the XML generated by HeroLab and convert it to JSON (not very difficult, there are web sites that will do it handily). I tried reworking the macro, to do a JSON.parse to create a javascript object that represents the character, figuring accessing the various properties of the object would be faster than parsing the Xml by hand. I took the same approach and read the JSON from the gmnotes field, only to find that even after doing replaces for all the character entities (%20, %32, etc).

I started looking into it and found the problem. When I pasted the JSON text into the gmnotes field, it had several arrays defined with square bracket characters ( "[" and "]"). These characters get stripped out when I save the token after pasting the JSON to the gmnotes field.

Is there a reason that those characters get stripped?

I can come up with a workaround, but would prefer to just paste the json and have it work.
November 05 (10 years ago)
The [ ] brackets are used to link to Handouts and such inside Roll20.
November 05 (10 years ago)
The Aaron
Roll20 Production Team
API Scripter
I have a workaround tailor made for you! =D

Base64 encoded JSON will work just fine and I have a module created for this already:

GIST: https://gist.github.com/shdwjk/e4c798c07070ad1f2da5
November 05 (10 years ago)
Thanks guys! That works perfectly! Easy to implement, too.

Morgan
November 05 (10 years ago)
The Aaron
Roll20 Production Team
API Scripter
No problem!
November 05 (10 years ago)
Ok, you guys were so helpful, here's another one. I'm using the createObj function to create a new character, providing just the name. When it runs, I get the error:

"ERROR: You cannot set the imgsrc or avatar of an object unless you use an image that is in your Roll20 Library. See the API documentation for more info."

The character is created in any event, so the script works, but I'm wondering why I get the error, and is it something to worry about.
November 05 (10 years ago)
The Aaron
Roll20 Production Team
API Scripter
I'm guessing your confusion stems from the fact that you aren't even trying to set an image. :)

I ran into this same issue with rollable tables. As best I can tell, the rules that govern setting images are these:
• When creating an object, the imgsrc must be a url to a user's personal library.
• Suppled image urls must be to the 'thumb' version of the image.

The spectacular part and cause of your error is the fact that the default of '' fails that first one and produces an error.

It's annoying but not really anything to worry about. I'm hoping they'll fix it at some point and make it so we can use image urls from the marketplace if the campaign owner has access to them.