JSON Object (Map) Vs Array

1,260 views
Skip to first unread message

Balamurugan

unread,
Jul 9, 2012, 10:11:58 AM7/9/12
to api-...@googlegroups.com
Hi,

I am having an idea to provide the JSON response in the form of array rather than Object (Key value map)

For example,

Consider a response for the list request ,Instead of sending response like
[
{
  "id" : 123,
  "name" : "Chessboard",
  "rate" : 100.00
  "description" : "description of board"
},
{
  "id" : 456,
  "name" : "Rhymes CD",
  "rate" : 200.00
  "description" : "Rhymes"
}
]

planning to send

{
 "header" : [ "id", "name", "rate", "description"],
 "data" : [
              [123, "Chessboard", 100.00, "description of board"],
              [456, "Rhymes CD", 200.00, "Rhymes"]
]
}

By this. I am able to get considerable size reduction for the response from server.

But unfortunately, I am not see such a response from any of the good API providers that we refer.

Am I missing anything? Is there any serious disadvantage of using array of data with header separated?

Please suggest.

Thanks
Balamurugan

Jon Moore

unread,
Jul 9, 2012, 10:16:20 AM7/9/12
to api-...@googlegroups.com
Actually, if you apply gzip compression, the second example is 150 bytes and the first is only 132 bytes.

Jon
--
........
Jon Moore

mca

unread,
Jul 9, 2012, 10:16:45 AM7/9/12
to api-...@googlegroups.com
If size reduction on the initial response is of paramount concern, you can drop a few more bytes from your example if you format it in text/csv

"id", "name", "rate", "description"
123, "Chessboard", 100.00, "description of board"
456, "Rhymes CD", 200.00, "Rhymes"


On Mon, Jul 9, 2012 at 10:11 AM, Balamurugan <nbalam...@gmail.com> wrote:

Enrique Amodeo

unread,
Jul 9, 2012, 10:43:25 AM7/9/12
to api-...@googlegroups.com
Think about the developer who needs to code a client that consumes
your json. For a JS developer the first form seems more natural than
the second.
If saving bandwitdh is critical for you, simply don't use JSON and
switch to other formats. Some suggestions:
a) BSON: http://bsonspec.org/
b) Message Pack: http://msgpack.org/
c) Google Protocol Buffer: http://code.google.com/p/protobuf/
Or simply switch on ZIP compression on your server and compare it to
these formats.
Cheers,
Enrique Amodeo.
Reply all
Reply to author
Forward
0 new messages