JSON falls flat when trying to define data types and serialize objects.
var foo1 = new Foo1();
foo1.bar1 = new Bar1();
var foo2 = new Foo2();
foo2.bar2 = new Bar2();
If you were to serialize that data using XML you might do this: <Foo1 name="foo1">
<Bar1 name="bar1"/>
</Foo1>
<Foo2 name="foo2">
<Bar2 name="bar2"/>
</Foo2>
But now what if you use JSON? You'll probably end up with something like this: {
"foo1" : {
"class" : "Foo1",
"@bar1" : {"class":"Bar1"}
},
"foo2" : {
"class" : "Foo2",
"@bar2" : {"class":"Bar2"}
}
}
Generally it makes sense to use XML for imperative data structures, and use JSON for functional data structures.