Compressed Json Javascript [closed]

2019-03-10 19:57发布

Currently I send JSON from an Ajax post to the server which is then converted to objects using the Jackson Mapper.

The format is like this

{"id":"780710","folderID":"42024","displayOrder":2},{"id":"780724","folderID":"42024","displayOrder":3}

What is the best JavaScript library to compress this data and will the Jackson mapper be able to handle the new format?

5条回答
爷的心禁止访问
2楼-- · 2019-03-10 20:33

JsonZipper is also Awesome for multiple similar repeated objects. It allows you to use an object in its' zipped state by only extracting one object by index from the array, so memory wise it is great as it will always only have extracted what you want.

Oh and you can actually compress on the go, so basically as you are generating data objects, you can compress them, leaving you to always have a small memory footprint.

Most other compression algorithms have to compress&extract all the data at once.

Note however: if your data is a Homogeneous Collection (Exactly Same keys then hpack will be better.)

查看更多
在下西门庆
3楼-- · 2019-03-10 20:39

As said by @JamWaffles, this is the best JSON is able to do concerning compression. And in your case (the line of code you delivered), compressing further may be overkill.

But if you have larger responses, and you want to save those bytes, have a look at

or

They are not JSON, but they serialize data to a smaller format (in most cases).

查看更多
女痞
4楼-- · 2019-03-10 20:46

Why not just enable gzip compression that browser and web servers support? This will very nicely compress data sizes, with very little explicit work.

查看更多
forever°为你锁心
5楼-- · 2019-03-10 20:49

According to this tweet by modec, compressing JSON is indeed possible, and provides better result than tested alternatives.

It's possible to handle JSON format with nodejs, and a recent open-source project just implemented a very fast compression algorithm for nodejs.

查看更多
小情绪 Triste *
6楼-- · 2019-03-10 20:49

You can use e.g. jsonh, successor of hpack which has benchmarks on web-resource-optimization. It helps, but the same site will also show you that gzip alone will probably be enough.

So to be clear, gzip works better than hpack, but combining them adds a little more compression.

查看更多
登录 后发表回答