How can I reduce the size of this JSON record?

1.2k Views Asked by At

I'm working on reducing the size of my database records. Each record is on average around 5Kb of which 97% is used by an single array property.

This array describe object on an image and their bounding box, described as a series of points:

[
    {
      "s": 0,
      "e": 6,
      "w": "Ihandle",
      "b": [
        { "x": 0.08816705336426914, "y": 0.1531684174855981 },
        { "x": 0.2523201856148492, "y": 0.15249068112504235 },
        { "x": 0.2523201856148492, "y": 0.17926126736699424 },
        { "x": 0.08816705336426914, "y": 0.17993900372754998 }
      ]
    },
    {
      "s": 8,
      "e": 16,
      "w": "financial",
      "b": [
        { "x": 0.08584686774941995, "y": 0.1762114537444934 },
        { "x": 0.25696055684454755, "y": 0.1762114537444934 },
        { "x": 0.25696055684454755, "y": 0.2016265672653338 },
        { "x": 0.08584686774941995, "y": 0.2016265672653338 }
      ]
    },
    {
      "s": 18,
      "e": 29,
      "w": "transactions",
      "b": [
        { "x": 0.016241299303944315, "y": 0.20060996272450016 },
        { "x": 0.25928074245939675, "y": 0.19959335818366655 },
        { "x": 0.25928074245939675, "y": 0.22636394442561844 },
        { "x": 0.016821345707656612, "y": 0.22738054896645205 }
      ]
    },

...
]

About these points:

  • always exactly 4 points
  • point not always parallel to each others
  • doesn't require more than 1/1000 precision

I was wondering, is there a way I can reduce the size of that payload? (end goal is to index those record in full text search service like Algolia)

1

There are 1 best solutions below

0
KYL3R On
  • You can minify the JSON, which could save a little bit of space. You can still pretty-print it in a formatted way.
  • If you don't need the full precision, you could remove some digits and shorten the numbers to something like "0.016821"
  • A Bounding box could be expressed like this: Point(x,y) + Width + Height. That would be 4 Numbers instead of 8!

edit: What about those coordinates? Numbers look like they represent a fraction of the screen width and height (like a canvas). Sure, you can lower the precision, but if your resolution is fixed you could use Integer numbers. "1024, 800" has a lot less characters compared to "0.016821345707656612, 0.22738054896645205".