Hi,
> What I'd like to see is:
>
> --> [
> {"jsonrpc": "2.0", "method": "sum", "params": [1,2,4], "id": "1"},
> {"jsonrpc": "2.0", "method"
> ]
> <-- [
> {"jsonrpc": "2.0", "result": 7, "id": "1"},
> {"jsonrpc": "2.0", "error": {"code": -32700, "message": "Parse error"}, "id": null}
> ]
the problem is, that it's difficult to determine where the error in the
JSONRPC-(batch-)request occurred, and that the 1st line is really
the complete, errorfree 1st request. What would you do e.g. in the following
case?
--> [
{"jsonrpc": "2.0", "id": "1", "method": "sum", "params": [1,2,4,]}
5]}
In addition, most JSON-decoders are non-streaming, so most JSON-decoders
couldn't parse the request at all, since it is invalid JSON. So, the
best choice here is to reject the whole batch and tell that there was
an error. Trying to guess where the error could have been and trying to
partially correct the error would make it much more complicated
and could result in unexpected errors.
> Wouldn't it be better if specification would give me a bit more freedom in
> case of malformed batch?
I would suggest something different: Do not use batch, but simply stream the
JSONRPC-requests.
As I said, most JSON-decoders are non-streaming, but can only decode a
complete, valid JSON-string. If you have a streaming JSON-decoder (or a
JSON-splitter), you don't need batches at all -- you can simply send several
requests over the same connection:
--> {"jsonrpc": "2.0", "method": "sum", "params": [1,2,4], "id": "1"}
--> {"jsonrpc": "2.0", "method"
<-- {"jsonrpc": "2.0", "result": 7, "id": "1"},
<-- {"jsonrpc": "2.0", "error": {"code": -32700, "message": "Parse error"}, "id": null}
best regards
Roland