www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - std.json parsing real numbers.

reply "khurshid" <khurshid.normuradov gmail.com> writes:
I just check  std.json for parsing real numbers.

import std.json;
import std.stdio: writeln;

int main()
{
	auto json = parseJSON("1        .24E          +1");
	writeln(toJSON(&json));
	return 0;
}

and
output:  12.4


It's bug or normal ?
Aug 08 2013
next sibling parent reply "MrSmith" <mrsmith33 yandex.ru> writes:
On Thursday, 8 August 2013 at 08:04:49 UTC, khurshid wrote:
 I just check  std.json for parsing real numbers.

 import std.json;
 import std.stdio: writeln;

 int main()
 {
 	auto json = parseJSON("1        .24E          +1");
 	writeln(toJSON(&json));
 	return 0;
 }

 and
 output:  12.4


 It's bug or normal ?
Yep, because 1.24E+1 is 12.4E0
Aug 08 2013
parent reply "khurshid" <khurshid.normuradov gmail.com> writes:
On Thursday, 8 August 2013 at 10:11:07 UTC, MrSmith wrote:
 On Thursday, 8 August 2013 at 08:04:49 UTC, khurshid wrote:
 I just check  std.json for parsing real numbers.

 import std.json;
 import std.stdio: writeln;

 int main()
 {
 	auto json = parseJSON("1        .24E          +1");
 	writeln(toJSON(&json));
 	return 0;
 }

 and
 output:  12.4


 It's bug or normal ?
Yep, because 1.24E+1 is 12.4E0
I wrote not a "1.24E+1", a "1 .24E +1" with leading spaces.
Aug 08 2013
parent reply "Borislav Kosharov" <bosak gmail.com> writes:
On Thursday, 8 August 2013 at 10:13:51 UTC, khurshid wrote:
 On Thursday, 8 August 2013 at 10:11:07 UTC, MrSmith wrote:
 On Thursday, 8 August 2013 at 08:04:49 UTC, khurshid wrote:
 I just check  std.json for parsing real numbers.

 import std.json;
 import std.stdio: writeln;

 int main()
 {
 	auto json = parseJSON("1        .24E          +1");
 	writeln(toJSON(&json));
 	return 0;
 }

 and
 output:  12.4


 It's bug or normal ?
Yep, because 1.24E+1 is 12.4E0
I wrote not a "1.24E+1", a "1 .24E +1" with leading spaces.
Well what should it be if it's not 12.4? If you think it should be 2.24 you are wrong. In JSON there are no additions or subtractions. It is only static data. It is just a format. And although JSON stands for JavaScriptObjectNotation it isn't JS. Even if {"key":1.24 + 1} is valid JS it is not valid JSON.
Aug 08 2013
next sibling parent reply Nick Sabalausky <SeeWebsiteToContactMe semitwist.com> writes:
On Thu, 08 Aug 2013 17:20:16 +0200
"Borislav Kosharov" <bosak gmail.com> wrote:

 On Thursday, 8 August 2013 at 10:13:51 UTC, khurshid wrote:
 On Thursday, 8 August 2013 at 10:11:07 UTC, MrSmith wrote:
 On Thursday, 8 August 2013 at 08:04:49 UTC, khurshid wrote:
 I just check  std.json for parsing real numbers.

 import std.json;
 import std.stdio: writeln;

 int main()
 {
 	auto json = parseJSON("1        .24E          +1");
 	writeln(toJSON(&json));
 	return 0;
 }

 and
 output:  12.4


 It's bug or normal ?
Yep, because 1.24E+1 is 12.4E0
I wrote not a "1.24E+1", a "1 .24E +1" with leading spaces.
Well what should it be if it's not 12.4?
A syntax error.
Aug 08 2013
parent reply "Borislav Kosharov" <boby_dsm abv.bg> writes:
On Thursday, 8 August 2013 at 16:05:56 UTC, Nick Sabalausky wrote:
 On Thu, 08 Aug 2013 17:20:16 +0200
 "Borislav Kosharov" <bosak gmail.com> wrote:

 On Thursday, 8 August 2013 at 10:13:51 UTC, khurshid wrote:
 On Thursday, 8 August 2013 at 10:11:07 UTC, MrSmith wrote:
 On Thursday, 8 August 2013 at 08:04:49 UTC, khurshid wrote:
 I just check  std.json for parsing real numbers.

 import std.json;
 import std.stdio: writeln;

 int main()
 {
 	auto json = parseJSON("1        .24E          +1");
 	writeln(toJSON(&json));
 	return 0;
 }

 and
 output:  12.4


 It's bug or normal ?
Yep, because 1.24E+1 is 12.4E0
I wrote not a "1.24E+1", a "1 .24E +1" with leading spaces.
Well what should it be if it's not 12.4?
A syntax error.
I don't think this would cause any problems. It would just throw syntax error because there is white-space between? It would be just annoying to get syntax error because of extra white-space. Maybe this is one of the situations where we should think "It's not a bug, it's a feature!" Unless there is a situation that would make no sense to work or something, it should be left like it is now.
Aug 08 2013
next sibling parent "Tofu Ninja" <emmons0 purdue.edu> writes:
On Thursday, 8 August 2013 at 18:46:17 UTC, Borislav Kosharov 
wrote:
 On Thursday, 8 August 2013 at 16:05:56 UTC, Nick Sabalausky 
 wrote:
 On Thu, 08 Aug 2013 17:20:16 +0200
 "Borislav Kosharov" <bosak gmail.com> wrote:

 On Thursday, 8 August 2013 at 10:13:51 UTC, khurshid wrote:
 On Thursday, 8 August 2013 at 10:11:07 UTC, MrSmith wrote:
 On Thursday, 8 August 2013 at 08:04:49 UTC, khurshid wrote:
 I just check  std.json for parsing real numbers.

 import std.json;
 import std.stdio: writeln;

 int main()
 {
 	auto json = parseJSON("1        .24E          +1");
 	writeln(toJSON(&json));
 	return 0;
 }

 and
 output:  12.4


 It's bug or normal ?
Yep, because 1.24E+1 is 12.4E0
I wrote not a "1.24E+1", a "1 .24E +1" with leading spaces.
Well what should it be if it's not 12.4?
A syntax error.
I don't think this would cause any problems. It would just throw syntax error because there is white-space between? It would be just annoying to get syntax error because of extra white-space. Maybe this is one of the situations where we should think "It's not a bug, it's a feature!" Unless there is a situation that would make no sense to work or something, it should be left like it is now.
Its not really a situation where we should deviate from the specs... it is starting to seem that the json specs say that there should be no white spaces and as this is a standard lib, we should conform to that
Aug 08 2013
prev sibling next sibling parent =?UTF-8?B?QWxpIMOHZWhyZWxp?= <acehreli yahoo.com> writes:
On 08/08/2013 11:46 AM, Borislav Kosharov wrote:
 I wrote not a "1.24E+1", a "1     .24E     +1"  with leading > 
spaces.
 Well what should it be if it's not 12.4?
A syntax error.
I don't think this would cause any problems. It would just throw syntax error because there is white-space between? It would be just annoying to get syntax error because of extra white-space. Maybe this is one of the situations where we should think "It's not a bug, it's a feature!" Unless there is a situation that would make no sense to work or something, it should be left like it is now.
How about integers? I wouldn't expect "4 2" to be parsed silently as 42. Ali
Aug 08 2013
prev sibling next sibling parent Nick Sabalausky <SeeWebsiteToContactMe semitwist.com> writes:
On Thu, 08 Aug 2013 20:46:15 +0200
"Borislav Kosharov" <boby_dsm abv.bg> wrote:

 On Thursday, 8 August 2013 at 16:05:56 UTC, Nick Sabalausky wrote:
 On Thu, 08 Aug 2013 17:20:16 +0200
 "Borislav Kosharov" <bosak gmail.com> wrote:

 On Thursday, 8 August 2013 at 10:13:51 UTC, khurshid wrote:
 I wrote not a "1.24E+1", a "1     .24E     +1"  with leading 
 spaces.
Well what should it be if it's not 12.4?
A syntax error.
I don't think this would cause any problems. It would just throw syntax error because there is white-space between? It would be just annoying to get syntax error because of extra white-space. Maybe this is one of the situations where we should think "It's not a bug, it's a feature!" Unless there is a situation that would make no sense to work or something, it should be left like it is now.
Specs should be adhered to strictly. Otherwise you can wind up in the "antirobustness principle" situation like late 90's HTML. Laxness begets more laxness...and then incompatibility bugs.
Aug 08 2013
prev sibling parent reply "H. S. Teoh" <hsteoh quickfur.ath.cx> writes:
On Thu, Aug 08, 2013 at 08:46:15PM +0200, Borislav Kosharov wrote:
 On Thursday, 8 August 2013 at 16:05:56 UTC, Nick Sabalausky wrote:
On Thu, 08 Aug 2013 17:20:16 +0200
"Borislav Kosharov" <bosak gmail.com> wrote:

On Thursday, 8 August 2013 at 10:13:51 UTC, khurshid wrote:
 On Thursday, 8 August 2013 at 10:11:07 UTC, MrSmith wrote:
 On Thursday, 8 August 2013 at 08:04:49 UTC, khurshid wrote:
 I just check  std.json for parsing real numbers.

 import std.json;
 import std.stdio: writeln;

 int main()
 {
 	auto json = parseJSON("1        .24E          +1");
 	writeln(toJSON(&json));
 	return 0;
 }

 and
 output:  12.4


 It's bug or normal ?
Yep, because 1.24E+1 is 12.4E0
I wrote not a "1.24E+1", a "1 .24E +1" with leading >
spaces. Well what should it be if it's not 12.4?
A syntax error.
I don't think this would cause any problems. It would just throw syntax error because there is white-space between? It would be just annoying to get syntax error because of extra white-space. Maybe this is one of the situations where we should think "It's not a bug, it's a feature!" Unless there is a situation that would make no sense to work or something, it should be left like it is now.
This makes std.json non-conformant to the JSON spec. What if the extra white-space is an indication of data corruption? We should not blindly accept it just because we can. T -- "Life is all a great joke, but only the brave ever get the point." -- Kenneth Rexroth
Aug 08 2013
parent reply "Borislav Kosharov" <boby_dsm abv.bg> writes:
On Saturday, 10 August 2013 at 18:28:31 UTC, H. S. Teoh wrote:
 On Thu, Aug 08, 2013 at 08:46:15PM +0200, Borislav Kosharov 
 wrote:
 On Thursday, 8 August 2013 at 16:05:56 UTC, Nick Sabalausky 
 wrote:
On Thu, 08 Aug 2013 17:20:16 +0200
"Borislav Kosharov" <bosak gmail.com> wrote:

On Thursday, 8 August 2013 at 10:13:51 UTC, khurshid wrote:
 On Thursday, 8 August 2013 at 10:11:07 UTC, MrSmith wrote:
 On Thursday, 8 August 2013 at 08:04:49 UTC, khurshid 
 wrote:
 I just check  std.json for parsing real numbers.

 import std.json;
 import std.stdio: writeln;

 int main()
 {
 	auto json = parseJSON("1        .24E          +1");
 	writeln(toJSON(&json));
 	return 0;
 }

 and
 output:  12.4


 It's bug or normal ?
Yep, because 1.24E+1 is 12.4E0
I wrote not a "1.24E+1", a "1 .24E +1" with leading >
spaces. Well what should it be if it's not 12.4?
A syntax error.
I don't think this would cause any problems. It would just throw syntax error because there is white-space between? It would be just annoying to get syntax error because of extra white-space. Maybe this is one of the situations where we should think "It's not a bug, it's a feature!" Unless there is a situation that would make no sense to work or something, it should be left like it is now.
This makes std.json non-conformant to the JSON spec. What if the extra white-space is an indication of data corruption? We should not blindly accept it just because we can. T
Sorry, I tough that white-space was allowed in JSON, but I didn't red the specification before posting. If that is what the spec says then I agree too to stay strict with it.
Aug 10 2013
parent "H. S. Teoh" <hsteoh quickfur.ath.cx> writes:
On Sat, Aug 10, 2013 at 09:18:42PM +0200, Borislav Kosharov wrote:
 On Saturday, 10 August 2013 at 18:28:31 UTC, H. S. Teoh wrote:
On Thu, Aug 08, 2013 at 08:46:15PM +0200, Borislav Kosharov wrote:
On Thursday, 8 August 2013 at 16:05:56 UTC, Nick Sabalausky
wrote:
On Thu, 08 Aug 2013 17:20:16 +0200
"Borislav Kosharov" <bosak gmail.com> wrote:

On Thursday, 8 August 2013 at 10:13:51 UTC, khurshid wrote:
 On Thursday, 8 August 2013 at 10:11:07 UTC, MrSmith wrote:
 On Thursday, 8 August 2013 at 08:04:49 UTC, khurshid >>>>
wrote:
 I just check  std.json for parsing real numbers.

 import std.json;
 import std.stdio: writeln;

 int main()
 {
 	auto json = parseJSON("1        .24E          +1");
 	writeln(toJSON(&json));
 	return 0;
 }

 and
 output:  12.4


 It's bug or normal ?
Yep, because 1.24E+1 is 12.4E0
I wrote not a "1.24E+1", a "1 .24E +1" with >>>
leading >
spaces.

Well what should it be if it's not 12.4?
A syntax error.
I don't think this would cause any problems. It would just throw syntax error because there is white-space between? It would be just annoying to get syntax error because of extra white-space. Maybe this is one of the situations where we should think "It's not a bug, it's a feature!" Unless there is a situation that would make no sense to work or something, it should be left like it is now.
This makes std.json non-conformant to the JSON spec. What if the extra white-space is an indication of data corruption? We should not blindly accept it just because we can. T
Sorry, I tough that white-space was allowed in JSON, but I didn't red the specification before posting. If that is what the spec says then I agree too to stay strict with it.
Whitespace is allowed only surrounding certain structural characters, which are specified in RFC4627 (http://www.ietf.org/rfc/rfc4627.txt, section 2) as: [ { ] } : , I take that to mean that everywhere else, whitespace is significant, so inserting spaces inside a float literal is an error. T -- Fact is stranger than fiction.
Aug 10 2013
prev sibling parent "H. S. Teoh" <hsteoh quickfur.ath.cx> writes:
On Thu, Aug 08, 2013 at 05:20:16PM +0200, Borislav Kosharov wrote:
 On Thursday, 8 August 2013 at 10:13:51 UTC, khurshid wrote:
On Thursday, 8 August 2013 at 10:11:07 UTC, MrSmith wrote:
On Thursday, 8 August 2013 at 08:04:49 UTC, khurshid wrote:
I just check  std.json for parsing real numbers.

import std.json;
import std.stdio: writeln;

int main()
{
	auto json = parseJSON("1        .24E          +1");
	writeln(toJSON(&json));
	return 0;
}

and
output:  12.4


It's bug or normal ?
Yep, because 1.24E+1 is 12.4E0
I wrote not a "1.24E+1", a "1 .24E +1" with leading spaces.
Well what should it be if it's not 12.4? If you think it should be 2.24 you are wrong.
If you think it should be 12.4, you're wrong too. This is illegal syntax according to the JSON spec and RFC 4627 (see sections 2 and 2.4: whitespace is not allowed inside a number literal). It should throw an exception, not return any value. T -- IBM = I Blame Microsoft
Aug 08 2013
prev sibling parent "Tyler Jameson Little" <beatgammit gmail.com> writes:
On Thursday, 8 August 2013 at 08:04:49 UTC, khurshid wrote:
 I just check  std.json for parsing real numbers.

 import std.json;
 import std.stdio: writeln;

 int main()
 {
 	auto json = parseJSON("1        .24E          +1");
 	writeln(toJSON(&json));
 	return 0;
 }

 and
 output:  12.4


 It's bug or normal ?
As mentioned in a different thread, it's a bug since it doesn't adhere to the JSON standard.
Aug 08 2013