Now that new javascript accepts binary numbers (i.e. 0b1111) should not JSON also? Or are they two separate entities?
console.log(Number.isNaN(0b1111); // = 'false' meaning it is a number
but
JSON.parse('{"a":0b1111}');
Does not work.
Now that new javascript accepts binary numbers (i.e. 0b1111) should not JSON also? Or are they two separate entities?
console.log(Number.isNaN(0b1111); // = 'false' meaning it is a number
but
JSON.parse('{"a":0b1111}');
Does not work.
JSON is deliberately designed to be a limited subset of Javascript syntax. This allows it to be used to represent common array and object formats while minimizing the complexity of the parsers. So while Javascript literal syntax allows many alternative ways of representing the same thing, JSON generally allows just one.
E.g. in Javascript, you can use either single or double quotes around strings, but JSON only allows double quotes. And quotes around the keys objects are optional in Javascript (if the key is a valid identifier), but they're required in JSON.
Changing JSON to allow more formats would be problematic, because it will cause compatibility problems with older parsers. So the JSON designers are not likely to extend it for something that isn't really needed. The only change that I think has been made recently is to officially allow top-level values that aren't objects or arrays; most parsers already accepted this already. So unless the authors of all the popular libraries add binary integers, they're not likely to bless this as part of the JSON specification.
echo json_encode() in a PHP script to output literals to be substituted directly into Javascript source code.JSON is not Javascript :)
Look at the grammar production for number at https://json.org/ (right column) and you'll see there is no such thing as binary literal numbers in JSON.
From MDN:
Binary numbers
Binary number syntax uses a leading zero followed by a lowercase or uppercase Latin letter "B" (0b or 0B).
What you have is a number literal of type binary. The assigned value is a number. That number is later used as decimal type (standard) in the object.
var object = { v: 0b1111 };
console.log(JSON.stringify(object));