I want my JSON service to return a boolean value. I know that returning only true
or false
is invalid JSON, so what is the best way to do this? I've thought of these options:
[true]
Or:
{ "response": true }
I prefer the latter one. Are there any best-practices for this?
true
is a perfectly valid JSON value, it's no worse than [true]
or { "response": true }
. Wrapping it into an object would be a good idea (and object is better than an array), because if one day you decide to add some more data to the response, you won't break all the clients that expect a pure boolean value.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With