jsonmod
JSON parser and encoder for Haxe. Based on TJSON library (by Jordan CM Wambaugh).
JSON format extended features:
- Single-quotes for strings.
- Identifiers not wrapped in quotes.
- C style comments support -
/*comment*/. - C++ style comments support -
//comment. - Dangling commas don't kill it (commas are even optional).
Features:
- Typed parsing using
RTTI(restore classes). @jsonIgnorefield meta to skip fields on serialization.Dateserialized as Float (usedDate.getTime()).- In "typed" mode
Datedeserialized from Float (usedDate.fromTime()). - Recursive self-references not supported (exception throws on serialization).
Basic using
import jsonmod.Json;
...
// parse string to object
var data = "{ key:'value' }";
var object = Json.parse(data);
// encode object to string
var json = Json.encode(object);
Advanced using
@:rtti // need for Json.parseTyped() to detect field types
class MyClass
{
@jsonIgnore // ignore `a` on serialization
var a = 1;
public var b = 2;
public function new() {}
}
var str = Json.encode(new MyClass()); // "{b:2}"
// parse with classes support
var parsedObject = Json.parseTyped("{ a:20, b:10 }", MyClass); // MyClass { a:20, b:10 }