Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to handle a JSON service that responds with a boolean value?

Tags:

json

rest

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?

like image 857
Justus Romijn Avatar asked Nov 21 '13 15:11

Justus Romijn


1 Answers

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.

like image 92
fdreger Avatar answered Oct 24 '22 03:10

fdreger