Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSON values 1 or 0 - int or boolean

Does JSON treat these all the same? Or are they a mix of Integers and booleans?

var data = {     "zero" : 0,     "one" : 1,     "false" : 0,     "true" : 1,     "0" : false,     "1" : true } 
like image 891
Phill Pafford Avatar asked Jun 30 '11 22:06

Phill Pafford


People also ask

Can JSON values be boolean?

JSON BooleansValues in JSON can be true/false.

Can JSON have integer values?

JSON does not have distinct types for integers and floating-point values. Therefore, the presence or absence of a decimal point is not enough to distinguish between integers and non-integers. For example, 1 and 1.0 are two ways to represent the same value in JSON.

How are numbers represented in JSON?

JSON numbers follow JavaScript's double-precision floating-point format. Represented in base 10 with no superfluous leading zeros (e.g. 67, 1, 100). Include digits between 0 and 9. Can be a negative number (e.g. -10 .

What is bool in JSON?

The boolean type matches only two special values: true and false . Note that values that evaluate to true or false , such as 1 and 0, are not accepted by the schema.


1 Answers

The values true and false are actual boolean values, the rest are integers. See http://json.org/ for more.

like image 182
Rob Agar Avatar answered Sep 19 '22 18:09

Rob Agar