The JSON-RPC standard uses JSON and adds some constraints. It says e.g.
The Response is expressed as a single JSON Object, with the following members:
- jsonrpc A String specifying the version of the JSON-RPC protocol. MUST be exactly "2.0"
...Hence, all valid JSON-RPC responses are valid JSON Objects, but not all valid JSON Objects are valid JSON-RPC responses.
But then, it is also perfectly legal if the JSON-RPC standard required that the order of the members MUST be the following: jsonrpc, id, result, error.
This is simply another constraint that reduces the set of possible result objects without breaking the JSON standard.
A constraint like this would not reduce the power of JSON-RPC but would simplify the life of many performance-aware developers out there.
To clear up your confusion, I provide another example:
Lets assume that there is a small database on the client with the tables "contacts" and "tasks". And the client wants to populate both tables with an rpc call batch:
--> [
{"jsonrpc": "2.0", "method": "get_contacts", "params": null, "id": "1"},
{"jsonrpc": "2.0", "method": "get_tasks", "params": null, "id": "2"}
]
If the client can be sure that the order of the members in the response is "jsonrpc, id, result", then it can determine the destination table before reading the result and insert one record after the other into the table while reading the input stream. Hence it uses constant memory, regardless of the size of the response. If the client detects a syntax error after the e.g. 234th entry, it can rollback the transaction and handle the error.
However, if the id might come after the result, the client has to read the whole result into memory and then determine the destination table and write the records down. In this case, the memory usage depends on the size of the response (which is not that nice).
I conclude:
It would be an advantage (for free) if the standard required that the order of the members in the response MUST be "jsonrpc, id, result, error".
For the request, it is important that the member "method" comes before the member "params" (
similar considerations).