Reducing size of data stored with JSON
I have data that I convert to JSON. I need storage to be very optimized but when I look at the JSON string there is a lot of wasted space. For example my single true of false gets converted to:
"testField":false
It might seem not much but I have a lot of data and it's a big problem when one byte of a true or false gets converted to something 15 times larger.
Is there anything I could do to stop this huge waste of space and to optimi开发者_开发技巧ze the way data is stored. Note that I don't really need it to be JSON. All I need is to take the data stored in a class and have it converted to a string that I can convert back later.
Check out MessagePack: http://msgpack.org/
I suppose you could change testField into an integer and set it to "0". That would be smaller than "false".
testField is the name of your property, no?
If you'd like that shorter, use a shorter property name, but you're still only having a Boolean returned as the value. I guess if you don't like true/false you can make sure a 0/1 is returned instead.
I would try to use a binary format (BSon), or even better, Google's Protocol Buffers
精彩评论