Wednesday, December 31, 2014

CSV to JSON

An RPG is driven by data.  There are stats of monsters, weapons, spells.  There are maps and dialog trees and quest checkpoints.  All that data has to be stored somewhere.  One approach is to come up with proprietary formats, creating ASCII text files that custom reader / writer methods.

But the defacto standard of data storage these days is JSON.  The great thing about JSON is you can use some nice .NET libraries to read/write it.  JSON.NET: http://james.newtonking.com/json

However, it can be a little cumbersome to pop it open in a text editor and edit the raw fields.  Ideally, the level designer could store all the game data in Excel CSV files, and translate to JSON with a single click.

I built CSVtoJSON to do just that.  https://github.com/tdonlan/CSVtoJSON

It's a .NET Command Line utility that takes in a CSV file and will output a JSON file, via command line arguments.  CSV is read via csvHelper: http://joshclose.github.io/CsvHelper/

CSVtoJSON.exe 'input.csv' 'output.json'

The first row (column names) of the CSV will be used for the JSON keys.

One of the nice features is that you can put raw JSON in a column.  The converter will read in the JSON, translate to a .NET object, then serialize it back out as valid JSON (instead of wrapping it in a string).

Overall its a nice tool that will come in handy later on in the game development process, when there's lots of tweaking to the enemies, items and abilities that make up the game.

No comments:

Post a Comment