9
I am thinking about using JSON in a project, because it is highly accepted and there are many libraries ready that encode and decode it in other objects (arrays, for example), but there is something that worries me.
Suppose a Web Service returns values from a database table called clientes
. Something like that:
"clientes":[
{"nome":"João", "sobrenome":"Silva"},
{"nome":"José", "sobrenome":"Barbosa"},
{"nome":"Maria", "sobrenome":"Joana"}
]
Now, suppose the table has 10 million lines and I need the Web Service to return a JSON object with all of them.
The size of the object would be huge. Therefore, it would take a lot of bandwidth to transfer the information.
I could compress the JSON object using gzip, but this would generate another problem: a high processing cost to compress the object.
I could invent a compact format and just use it. But I would lose all the facilities offered by libraries dealing with JSON objects. In addition, it would be a non-standard design, which would make it difficult to maintain.
There is a solution to this dilemma?
I was thinking... maybe there is a differentiated JSON format that is accepted by libraries, and that is specific to the cases where data names are constant.
For example, something like this:
"clientes":[
{$"nome", "sobrenome"$},
{"João", "Silva"},
{"José", "Barbosa"},
{"Maria", "Joana"}
]
There is such a thing?
If not, what would be the best solution? I need to return large objects and would also use a common format to transfer them.
+1 for demystifying JSON as being more compact format, among other things.
– Bacco