JSON without the unnecessary quotes would probably work quite nicely.
Cas
JSON without the unnecessary quotes would probably work quite nicely.
Cas
Just say thanks! 8)
JSON is like. YAML is pretty good. XML blows hard. I like JSON because it’s closest to the data structures I expect to see in memory. There are a lot of parsers that will just turn {} into HashMap and [] into Array. Then it’s ultra easy to go through the data in code. I also find it very readable. I agree the quotes that can be annoying, especially because in straight javascript you don’t even need them ( {key: “value”} is totally valid). I personally wouldn’t make my own version of it though because then you can’t use convenient sites like jsonlint.com and the sort.
The code looks nifty enough. I personally have never found much benefit from taking code from other people, but who knows. Maybe if I decide to use a VBO I’ll look into your approach.
I don’t find alternatives to XML readable. Previously I didn’t like XML, but realized it was mostly because of bad schema that isn’t human friendly. If someone take care to make it nice (eg. more usage of attributes, no DTD/CDATA and other mess, etc) then it’s quite nice actually. The verbosity and syntax also make more obvious what is data and what is the rest.
Hm it’s subtle but I find this more readable and certainly a bit easier to type and probably parse too than the XML alternative:
<animation name="crab2.animation">
<label id="start"/>
<frame i="spriteimage.crab2_01" d="1"/>
<frame i="spriteimage.crab2_02" d="1"/>
<frame i="spriteimage.crab2_03" d="1"/>
<frame i="spriteimage.crab2_04" d="1"/>
<random>
<dest>start</dest>
<dest>start</dest>
<dest>start</dest>
<dest>start</dest>
<dest>start</dest>
<dest>start</dest>
<dest>start</dest>
<dest>start</dest>
<dest>pinch</dest>
</random>
<label id="pinch"/>
<frame i="spriteimage.crab2_05" d="1"/>
<frame i="spriteimage.crab2_06" d="1"/>
<frame i="spriteimage.crab2_07" d="1"/>
<frame i="spriteimage.crab2_08" d="1"/>
<frame i="spriteimage.crab2_05" d="1"/>
<frame i="spriteimage.crab2_06" d="1"/>
<frame i="spriteimage.crab2_07" d="1"/>
<frame i="spriteimage.crab2_08" d="1"/>
<frame i="spriteimage.crab2_05" d="1"/>
<frame i="spriteimage.crab2_06" d="1"/>
<frame i="spriteimage.crab2_07" d="1"/>
<frame i="spriteimage.crab2_08" d="1"/>
<goto id="start"/>
</animation>
animation {
name: crab2.animation
label { id: start}
frame { i: spriteimage.crab2_01 d: 1 }
frame { i: spriteimage.crab2_02 d: 1 }
frame { i: spriteimage.crab2_03 d: 1 }
frame { i: spriteimage.crab2_04 d: 1 }
random {
dest "start"
dest "start"
dest "start"
dest "start"
dest "start"
dest "start"
dest "start"
dest "start"
dest "pinch"
}
label { id: pinch }
frame { i: spriteimage.crab2_05 d:1 }
frame { i: spriteimage.crab2_06 d:1 }
frame { i: spriteimage.crab2_07 d:1 }
frame { i: spriteimage.crab2_08 d:1 }
frame { i: spriteimage.crab2_05 d:1 }
frame { i: spriteimage.crab2_06 d:1 }
frame { i: spriteimage.crab2_07 d:1 }
frame { i: spriteimage.crab2_08 d:1 }
frame { i: spriteimage.crab2_05 d:1 }
frame { i: spriteimage.crab2_06 d:1 }
frame { i: spriteimage.crab2_07 d:1 }
frame { i: spriteimage.crab2_08 d:1 }
goto { id: start }
}
Cas
JSON without the unnecessary quotes would probably work quite nicely.
Cas
Quite agree! The patch script syntax I developed for Praxis is influenced partly by JSON, but more as if it had been called TON - (ie. TCL Object Notation). The structured string approach of a typical TCL parser means no colons, and no quotes unless the key or value has whitespace. I find this simple, quick and intuitive to work with by hand - unlike XML!
Obviously, what I have is useless outside Praxis as is, but the general principle is pretty simple.
I always wonder if a LISP like notation would be nice for games. One could easily combine data with some light logic and one could even precompile data for faster loading. I never used Clojure, I wonder how big its jar is. (edit: the slim version is 840kb)
Json could also be simplefied to:
animation {
name: crab2.animation,
parts: [
{name: "start", d:1, base: "spriteimage.crab2_", frames: ["01","02","03","04"]},
{name: "pinch", d:1, base: "spriteimage.crab2_", frames: ["05","06","07","08","05","06","07","08","05","06","07","08"]}
],
loop: [
{item: "start", chance:"100%"},
{item: "pinch", chance:"15%"}
]
}
That wouldn’t map very well to my internal structures though
Cas
Here’s why XML > sexps (sometimes): There’s a syntax error in the code below. Tell me which construct got too many close parens:
((foo bar (blah (foo (abc def) blah (foo (xyzzy abcd)))))))
Okay, it’s contrived. But the fact is, no matter how meaningful the data, the parser has to get all the way to the end to report that there’s a balancing error, and it still can’t tell you where it is
JSON without the unnecessary quotes would probably work quite nicely.
A couple weeks ago I pulled my JSON stuff out of libgdx for standalone use:
http://code.google.com/p/jsonbeans/
It is a tiny lib that round trips objects <-> JSON automatically. It can also parse into map/lists/strings/floats if you prefer. You can do “json.setOutputType(OutputType.minimal);” and get a JSON-like data format that only has quotes where needed. I hadn’t thought about making some commas optional, I’ll give that some thought. I haven’t benchmarked it, but performance should be reasonable. Parsing is done in one pass using a Ragel generated state machine, but I didn’t bother to support streaming. Emitting is streamed. Some speed could be gained by using ReflectASM for the reflection.
Ooh, that’s nice, Nate. I use SBJSON in Objective-C and haven’t done much in Java so I didn’t have an equivalent library to use.
This is awesome Thank you!