News for hackers. Stuff that matters.
Re:Ask HN: Is there a way to compress repeated JSON objects? by Herostwist on Tuesday July 05, 2016 @10:10AM (#12036515)
If this is for a public api i would simply enable gzip and call it a day.

if this is for internal use you have a few options. although there is automatic way of reusing or referencing objects within json you can construct your own model using references.

One technique i have used in the past for a smaller memory footprint is to have an data array and then reference index positions within it.

e.g.

  {
    "items": [
    {
      "foo": 0,
      "bar": {
        "desc": 1,
        "other": 2
      }
    },
    {
      "foo": 3,
      "bar": {
        "desc": 1,
        "other": 2
      }
    },
    "data": [
      "foo bar",
      "some really long data",
      "lots more data",
      "not foobar",
    ]
 }
If you are free to use alternative serialisation methods i would recommend you look at protocol buffers.

https://developers.google.com/protocol-buffers/

There are no comments on this comment yet.