Reputation: 16059
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?
Upvotes: 18
Views: 18621
Reputation: 12505
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.
Upvotes: 16