Newtonsoft.json: Int parsing not working properly

Created on 24 Oct 2016  路  8Comments  路  Source: JamesNK/Newtonsoft.Json

We are passing 0000011 or 011 or 0011 etc in integer type parameter (C#). It is getting de-serialized to 9.
If we are passing 000012 or 012 or 0012 etc it is getting de-serialized to 10.

Please check this issue.

Most helpful comment

You shouldn't have done that (see my answer to the StackOverflow question). However, since you did that you should at least document the non-standard extensions that you have made to the JSON spec. I can't find any mention of the word "octal" when I search the Json.NET(using the search box here: http://www.newtonsoft.com/json/help/html/Introduction.htm) So I presume that it is not documented.

I would also suggest that you implement a "strict" option to turn off your non-standard extensions. In this case, it should treat leading zeros as an error, since that is what the JSON spec says.

All 8 comments

Version 6.0,3, using with Web API 2.2

Because of leading zeros they're octal.

Yes it does, but Json.NET allows some non-JSON spec things when reading JSON.

When writing JSON it conforms to the spec.

You shouldn't have done that (see my answer to the StackOverflow question). However, since you did that you should at least document the non-standard extensions that you have made to the JSON spec. I can't find any mention of the word "octal" when I search the Json.NET(using the search box here: http://www.newtonsoft.com/json/help/html/Introduction.htm) So I presume that it is not documented.

I would also suggest that you implement a "strict" option to turn off your non-standard extensions. In this case, it should treat leading zeros as an error, since that is what the JSON spec says.

Hello!

I just encountered this "problem".
Was there added something to make it work?

Thank you!
Stefan

@lonutstef, we changed type to string and converted to int in API code.

@ajaychoudhary01 Thank you for response!
So the problem shouldn't be encountered anymore, or it was decided to remain like this?

EIDT:
Sorry, I forgot to check the names. I thought you were one of the Newtonsoft.Json developers.

Such a change won't help us, so we will have to accept the bug.

Was this page helpful?
0 / 5 - 0 ratings