jsonmod

JSON serializer/deserializer. Support identifiers without quotes, comments, single quotes and typed parsing (like `Newtonsoft.Json` library in C#). Based on `tjson` library.
https://bitbucket.org/yar3333/haxe-jsonmod

To install, run:

haxelib install jsonmod 1.1.0 

See using Haxelib in Haxelib documentation for more information.

README.md

jsonmod

JSON parser and encoder for Haxe. Based on TJSON library (by Jordan CM Wambaugh).

JSON format extended features:

  1. Single-quotes for strings.
  2. Identifiers not wrapped in quotes.
  3. C style comments support - /*comment*/.
  4. C++ style comments support - //comment.
  5. Dangling commas don't kill it (commas are even optional).

Features:

  • Typed parsing using RTTI (restore classes).
  • @jsonIgnore field meta to skip fields on serialization.
  • Date serialized as Float (used Date.getTime()).
  • In "typed" mode Date deserialized from Float (used Date.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 }
Contributors
yar3333
Version
1.1.0
Published
1 week ago
License
BSD

All libraries are free

Every month, more than thousand developers use haxelib to find, share, and reuse code — and assemble it in powerful new ways. Enjoy Haxe; It is great!

Explore Haxe

Haxe Manual

Haxe Code Cookbook

Haxe API documentation

You can try Haxe in the browser! try.haxe.org

Join us on Github!

Haxe is being developed on GitHub. Feel free to contribute or report issues to our projects.

Haxe on Github