I'm thinking of using JSON in a project, as it is highly accepted and there are many ready-made libraries that encode and decode it into other objects (arrays, for example), but there is something that worries me.
Suppose a Web Service returns values from a database table named clientes
. Something like this:
"clientes":[
{"nome":"João", "sobrenome":"Silva"},
{"nome":"José", "sobrenome":"Barbosa"},
{"nome":"Maria", "sobrenome":"Joana"}
]
Now, suppose the table has 10 million rows and I need the Web Service to return a JSON object with all of them.
The size of the object would be huge. So 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 cost of processing to compress the object.
I could invent a compact format and simply use it. But I would lose all the facilities offered by libraries dealing with JSON objects. Also, it would be a non-standard project, which would make it difficult to maintain.
Is there a solution to this dilemma?
I was thinking ... maybe there is a differentiated JSON format that is supported by libraries, and is specific to cases where the data names are constant.
For example, something like this:
"clientes":[
{$"nome", "sobrenome"$},
{"João", "Silva"},
{"José", "Barbosa"},
{"Maria", "Joana"}
]
Is there something like this?
If not, what would be the best solution? I need to return large objects and I would also like to use a common format to transfer them.