As known, JSON is lighter data format, than XML and it is more preferable to use. But when you transfer big arrays of objects with the same structure, JSON is overload with data too. For example:
[
{
name: 'John',
surname: 'Smith',
info: { age: 25, comments: '' }
},
{
name: 'Sam',
surname: 'Black',
info: { age: 27, comments: '' }
},
{
name: 'Tom',
surname: 'Lewis',
info: { age: 21, comments: '' }
}
]
name
, surname
, age
and comments
triple declaration is useless, if I exactly know, that every array object has the same structure.
Is there any data format, that can minify such array data and be flexible enough?
Admittedly, this is a hackish solution, but we've used it and it works. You can flatten everything into arrays. For example, the above would be represented as:
[
['John','Smith',[24,'']],
['Sam','Black',[27,'']],
['Tom','Lewis',[21,'']]
]
The downside is that on serializing/deserializing, you have to do some custom logic. However, this does result in additional savings for a text-based solution, and Ray is right -- if you really want maximal savings, binary is the way to go.