Jump to content
sentry0

JSON Export Template

Recommended Posts

I'm attempting to build a JSON export template and am having some success so far.  I've hit a bit of a snag though with characteristics not exporting properly...see the below snippet.

 

<!--TEMPLATE_NAME-->6E JSON Export<!--/TEMPLATE_NAME-->
<!--TEMPLATE_DESCRIPTION-->
    <p>A JSON template for the Hero System 6th Edition by sentry0</p>
    <p>
        Version 1.0.0 (2018-02-17)
      <!--FILE_EXTENSION-->json<!--/FILE_EXTENSION-->
    </p>
<!--/TEMPLATE_DESCRIPTION-->
{
    name: '<!--CHARACTER_NAME-->',
    characteristics: {
        strength: {
            total: '<!--STR--><!--STR_TOTAL--><!/--STR-->',
            cost: '<!--STR--><!--STR_COST--><!/--STR-->',
            roll: '<!--STR--><!--STR_ROLL--><!/--STR-->',
            notes: '<!--STR--><!--STR_NOTES--><!/--STR-->'
        }
    },
    movement: {
        running: '<!--RUNNING--><!--RUNNING_TOTAL-->[<!--IF_RUNNING--><!--RUNNING_TOTAL_NONCOMBAT--><!--/IF_RUNNING--> NC]<!--/RUNNING-->'
    }
}

 

The "name" and "running" properties populate correctly but I can't seem to get any of the strength properties to work.

 

Here's what HD is outputting for me:

 

{
	name: 'Edward Lightbinder',
	characteristics: {
		strength: {
			total: '<!--STR--><!--STR_TOTAL--><!/--STR-->',
			cost: '<!--STR--><!--STR_COST--><!/--STR-->',
			roll: '<!--STR--><!--STR_ROLL--><!/--STR-->',
			notes: '<!--STR--><!--STR_NOTES--><!/--STR-->'
		}
	},
	movement: {
		running: '6"[12" NC]'
	}
}

 

Share this post


Link to post
Share on other sites

Edit:  never mind -- it was simpler than what I originally posted.

 

<!/--STR-->

That's where your problem is.  Replace it with the correct end tag:

<!--/STR-->

Share this post


Link to post
Share on other sites

My export template is sort of working, it's producing invalid JSON because some fields contain a single quote which happens to be what I'm using to quote my values.  I could switch to double quotes but it doesn't address the root issue which is if a player uses a single (or double quote) they will produce broken JSON.

 

Is there anyway for my to get like an XML dump from HD that I could use for further parsing?

Share this post


Link to post
Share on other sites

I've settled on a tab separated dump...it's not pretty but it should work for what I need it to :)

 

If there's a low effort way to get an XML dump out of HD I would much prefer that though. 

Share this post


Link to post
Share on other sites

What I was trying to say is if you have some magical way to get the data out of HD and into a machine readable format I would take it.  If nothing like that exists then I'll just keep moving down the TSV path

 

The XML format would have the same issue as JSON, it would actually probably be worse because of the amount of special characters you would have to watch out for.

Share this post


Link to post
Share on other sites

Good point about the  <![CDATA[]]> tags, totally forgot about that.

 

It's cool, I'll create an XML template...thanks again for your help.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×