Note that JSON-RPC only defines the protocol; it does not (and should
not) define language-specific implementation-details.
But in my opinion, the best way for "no return value" would be to return
null (both in 1.0 and in 2.0).
e.g.:
- JSON-RPC 2.0: {"jsonrpc": "2.0", "result": null, "id": 1}
- JSON-RPC 1.0: {"result": null, "error": null, "id": 1}
regards,
Roland
> Well my first thought was also for null but people often expect
> procedure not intended to return a value, return true or false to say
> if it processed well or not
If the return-value should tell the user whether the procedure was
"successful" or not, then the procedure should return such a value;
but if the procedure does not have a return-value, then the user may
not use the return-value in crude ways but has to read the
procedure-documentation.
> So if this kind of procedure return {} when there was no error it will
> be interpreted as true, otherwise the result property won't exists and
> will return undefined that will be interpreted as false.
No! This is wrong (and additionally very bad practice).
Remember that JSON-RPC is language-independent. You may not assume
that the client uses the same progamming-language as the server!
So:
- True, False, "undefined" and an empty dictionary are completele
different values.
If you e.g. try to convert an empty dictionary ("{}") to a boolean
value, some languages may return True, others return False and others
may even throw an exception/error etc.
- If a procedure without a return-value wants to report an error in a
JSON-RPC-Response, it has to use the "error"-field.
> If it return null when the call was successful, the client will have
> to check between undefined and null or to check if the error property
> is undefined or null (JSON-RPC 2 or 1). It's a little more work to do
> (even if often preferable)
A JSON-RPC-Client *always* has to check the Response, and its "result"-
and "error"-fields.
regards,
Roland