Is 081105004 a number for JSON?

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
bhall2001
Posts: 109
Joined: Thu Oct 30, 2014 3:54 pm

Is 081105004 a number for JSON?

Post by bhall2001 » Mon Oct 05, 2015 12:53 pm

I happened to take a json file created by easyJson and run it through a JSON lint program. The program reported an error with a number not being a number. The errant data is a UUID created with a simple formula YYMMDDXXX ( JSON object --- "CRN":081105004 ). The UUID can not be changed as it's a data element from an external source that is out of my control.

Livecode's "is a number" returns true for the above. When I read the JSON spec (json.org) I think I'm seeing that if a number starts with a 0 it must have a "." in it and an integer can not start with a 0? Is that the case?

So is 081105004 a number or a string for JSON? Is "put 081105004 is a number" reporting true the correct answer in Livecode?

Just curious,
Bob

JacobS
Posts: 58
Joined: Mon Aug 20, 2012 8:41 pm

Re: Is 081105004 a number for JSON?

Post by JacobS » Mon Nov 02, 2015 2:39 pm

Bob,

Yes, you're right. JSON specifications do not allow leading zeros on numbers without a decimal point. See section 8 on page 3 of http://www.ecma-international.org/publi ... MA-404.pdf.

LiveCode doesn't have this restriction on numbers, so when you do

Code: Select all

put 081105004 is a number
it will return true. This is expected.

As far as your issue goes, it seems to me that your UUID is really a string and not a number. If it were truly a number the leading zero wouldn't matter! I'm not sure if you have control over how the UUID is formatted when it is returned from the external source, but it really should be a string.

Hope that helps,
Jacob

Post Reply