Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length

 
Advanced search

1075930 Posts in 44152 Topics- by 36119 Members - Latest Member: Royalhandstudios

December 29, 2014, 04:07:04 PM
TIGSource ForumsDeveloperTechnical (Moderators: Glaiel-Gamer, ThemsAllTook)C++ JSON library
Pages: [1]
Print
Author Topic: C++ JSON library  (Read 3399 times)
madbranch
Level 0
*



View Profile
« on: June 01, 2011, 10:15:17 AM »

Hi,
My friends I have been working on a game engine project (RedBox engine) and recently we were looking at the possibilities for serialization/deserialization for many purposes in the engine. We have looked at XML and JSON libraries in C++. For XML, the choice is pretty simple, we went with TinyXML which is great for our needs, but we've had some problems with finding a good JSON library that felt clean enough, was object oriented and didn't require Boost.

So like any good developer, I decided to roll with our own JSON library. I've started it last week and currently have a prototype that is starting to be stable and I'd like to know what people think of it...

If anyone's interested in reading and writing JSON in C++, you can check out my library I named JsonBox (to fit with our engine's name, RedBox, lol). It uses a part of code from our engine to encode unicode characters to UTF8, so i copied it in the repository to simplify its use.

https://bitbucket.org/madbranch/jsonbox

Right now it reads and writes with a recursive algorithm, which might not be the brightest idea, but I'm looking at the possibilities to change that.

If you still have questions after reading this post and the README, I'd be glad to answer them.

What do people think of this yet-another-json-reading-library ?
Logged
mcc
Level 10
*****


glitch


View Profile WWW Email
« Reply #1 on: June 01, 2011, 11:00:59 AM »

Omg, looking forward to checking this out. I've been looking for something like this...
Logged

My projects:<br />Games: Jumpman Retro-futuristic platforming iJumpman iPhone version Drumcircle PC+smartphone music toy<br />More: RUN HELLO
Vino
Level 3
***


View Profile Email
« Reply #2 on: June 01, 2011, 09:59:24 PM »

I looked into a bunch of JSON libraries for my game when I wanted to start serializing game scripts and data to and from the hard drive. In the end I decided that even JSON was too heavyweight for me and I went with a custom scripting engine that only took me a few hours to write. The syntax is stupid simple so my artist can work easily with it (not that he's stupid) and the code is ridiculously small. I try not to reinvent the wheel but I think I made a good choice there.

Sorry I guess none of this has to do with your library. Looks neat though  Smiley Hand Thumbs Up Right
Logged

Hima
Level 4
****


OM NOM NOM


View Profile WWW Email
« Reply #3 on: June 01, 2011, 10:21:19 PM »

Have you tried this?   https://github.com/MJPA/SimpleJSON
It's C++, lightweight and requires no 3rd party libraries such as boost. Seems to fit your requirement quite well!

Anyway, I think it's always good to have an option. I might write a wrapper for Monkey and C++ JSON library so I'll see if it works well with your library.
Logged

Vino
Level 3
***


View Profile Email
« Reply #4 on: June 01, 2011, 11:50:22 PM »

My problem wasn't just with the JSON library but also with JSON itself. This is JSON:

Code:
{"menu": {
  "id": "file",
  "value": "File",
  "popup": {
    "menuitem": [
      {"value": "New", "onclick": "CreateNewDoc()"},
      {"value": "Open", "onclick": "OpenDoc()"},
      {"value": "Close", "onclick": "CloseDoc()"}
    ]
  }
}}

This is my markup:

Code:
Entity
{
Class: BugTurret
Team: Hackers
Position: -57, 11
Angle: 0

Output: OnBecomeFullyVisible
{
Target: instructor
Input: DisplayLesson
Args: mission-1-turret-spotted
Kill: yes
}
}

Since JSON is really just a Javascript array it's a bit conceptually more difficult and easier to fuck up if you're just an artist trying to install a new sprite or a writer trying to add a new page of dialogue. Miss a comma and JSON isn't very forgiving.
Logged

Hima
Level 4
****


OM NOM NOM


View Profile WWW Email
« Reply #5 on: June 02, 2011, 12:36:07 AM »

I was suggested that the safest way for artists/writers/non-programmers to deal with this is to do it in excel, and then try to find someway to convert the excel file to JSON.

If you use Google Docs, there is a widget that will allow you to do just that. It's hard to miss a comma in excel Smiley
Logged

BorisTheBrave
Level 10
*****


View Profile WWW
« Reply #6 on: June 02, 2011, 07:44:25 AM »

My problem wasn't just with the JSON library but also with JSON itself.
Sounds like you want YAML.
Logged
madbranch
Level 0
*



View Profile
« Reply #7 on: June 02, 2011, 09:54:36 AM »

YAML does indeed look interesting to use.

But as it says in http://yaml.org/spec/1.2/spec.html#id2759572 in the specification, YAML really aims at human readability at the cost of ease of parsing, writing and portability. We went with JSON because one of our engine's main objective is extreme portability.
Like right now, it works on Windows, Linux, Mac OS, iOS and just recently Haiku (took like 2 hours to setup). We're currently working to make the engine work on Android.

YAML would have probably been fine too and we might actually look into implementing it later.

Excel would probably be cool, but isn't it a bit of a heavy format? Depending on your project, needing a google widget might not always be awesome lol
Logged
Vino
Level 3
***


View Profile Email
« Reply #8 on: June 02, 2011, 12:09:38 PM »

Yeah I considered YAML too but it was still a bit too technical for me.

And I really like that spreadsheet idea.
Logged

Hima
Level 4
****


OM NOM NOM


View Profile WWW Email
« Reply #9 on: June 02, 2011, 03:57:24 PM »

Right, spreadsheet! People around here call it excel file so the word escaped me  Facepalm
Anyway, by excel file I mean any spreadsheet. And you don't need to include the original file in your game, you include the translated JSON from that spreadsheet. The google widgetgadget do the conversion from spreadsheet -> JSON for you then you can copy'n paste that JSON into a text file and use that in your game Smiley

Here's a website that tell you how to do it
http://blog.pamelafox.org/2009/05/how-to-convert-google-spreadsheet-into.html
Logged

Tycho Brahe
Level 10
*****

λx.x


View Profile
« Reply #10 on: June 03, 2011, 05:04:31 PM »

Nice! I looked at json for my last project, but couldn't really be bothered to take the time to work it out and find a nice library. You should contact the json people and get listed on their frontpage, it would really increase your exposure, and thus testing base.
Logged
madbranch
Level 0
*



View Profile
« Reply #11 on: June 08, 2011, 08:15:47 AM »

I like your idea 14113, I hadn't thought of it lol. So I prepared my repository a bit and I contacted Douglas Crockford. Now my library is available through http://www.json.org in the list of C++ JSON library at the bottom.   :D
Logged
Tycho Brahe
Level 10
*****

λx.x


View Profile
« Reply #12 on: June 08, 2011, 10:16:53 AM »

I like your idea 14113, I hadn't thought of it lol. So I prepared my repository a bit and I contacted Douglas Crockford. Now my library is available through http://www.json.org in the list of C++ JSON library at the bottom.   :D
Awesome!
Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic