Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does JSON allow positive sign for numbers?

After examining the JSON.org railroad (grammar) definition, the number definition provides the negative sign (-), but omits recognizing the positive (+) sign - is this an omission from the diagram, or does JSON disallow postitive sign (+) for numbers?

The exponent allows optional positive (+) and negative (-) signs, so it would seem to save little to provide recognition of (+) for the number...

like image 244
ChuckCottrill Avatar asked Oct 31 '14 03:10

ChuckCottrill


1 Answers

No, it doesn't.

Besides the grammar on json.org, JSON definitions are also provided by

  • the ECMAScript Language definition, 5.1 Edition of June 2011
  • RFC 7159 of March 2014

Concerning notation of signed numbers, they are all consistent. The former has

JSONNumber :: -? DecimalIntegerLiteral JSONFraction? ExponentPart?

while the latter says

number = [ minus ] int [ frac ] [ exp ]

Also all of these specifications allow an optional plus sign in the exponent, but none permits a plus sign to precede the numeric literal.

like image 70
Gunther Avatar answered Sep 19 '22 12:09

Gunther