Serialize JavaScript object tree to XML or JSON

I wonder whether some JavaScript objects serialization exists in one of the top JavaScript frameworks.
But looks like there is no any framework that supports flexible and powerful serialization. So I try to introduce some concepts I'm thinking of and how to implement them.

  • Serialize objects to various formats, from human-readable Json and Xml, to some compact binary formats.
  • Of course, exact object type should be restored during deseralization.
  • It should be possible to serialize/deserialize a tree of objects.
  • Serializer should detect circular references.
  • Objects should support custom serialization/deserialization methods.
  • Configuration options should allow the developer to change name of property in serialization result,
    mark some properties as non-serializable, support getters and setters for properties and so on.

read more about concepts...

Download
source code

Example

// Define class constructor
var SampleObject1 = function()
{
	this.name = 'MySampleObject';
	this.id = 1;
	this.seed = 1.009;
	this.createdAt = new Date();
	this.obj = null;
};

// Create instance of serializer
var serializer = new Ant.Serializer();

// Register SampleObject1, so serializer gets to know how to deal with such objects
serializer.register('SampleObject1', SampleObject1);

// Create data that will be serialized
var object = new SampleObject1();
object.obj = new SampleObject1();

// Serialize and get string representation
var xml = serializer.save(object).toString();

// Displays (formatting is changed):
// <SampleObject1>
//	<name type="string">MySampleObject</name>
//	<id type="number">1</id>
//	<seed type="number">1.009</seed>
//	<createdAt>
//		<Date value="2007-7-26T20:31:24.156"/>
//	</createdAt>
//	<obj>
//		<SampleObject1>
//			<name type="string">MySampleObject</name>
//			<id type="number">1</id>
//			<seed type="number">1.009</seed>
//			<createdAt>
//				<Date value="2007-7-26T20:31:24.156"/>
//			</createdAt>
//			<obj/>
//		</SampleObject1>
//	</obj>
// </SampleObject1>
WScript.echo(xml);

// Displays: MySampleObject
WScript.echo(serializer.load(xml).name);

more examples...