Bug 4148 - JavaScriptSerializer invalid json primitive
Summary: JavaScriptSerializer invalid json primitive
Alias: None
Product: Class Libraries
Classification: Mono
Component: System.Web ()
Version: 2.10.x
Hardware: PC Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: marcos.henrich
Depends on:
Reported: 2012-03-29 08:11 UTC by Alex Sinm
Modified: 2015-08-10 12:23 UTC (History)
5 users (show)

Is this bug a regression?: ---
Last known good build:

Fix the crash at jsondeserializer parsing keywords with trailing spaices (1.15 KB, patch)
2013-02-18 05:45 UTC, Salvador Alemany

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Alex Sinm 2012-03-29 08:11:39 UTC
JavaScriptSerializer.Deserialize throws invalid json primitive exception
Comment 1 Alex Sinm 2012-03-29 08:12:19 UTC
class foo {public bool bar;}
void test() {
    string foo_json = "{\"bar\" : true\n}";
    foo foo_obj = (new JavaScriptSerializer).Deserialize<foo>(foo_json);

Throws "Invalid json primitive : true" while there is trailing whitespace just after the 'true'.
Comment 2 Salvador Alemany 2013-02-18 05:45:26 UTC
Created attachment 3403 [details]
Fix the crash at jsondeserializer parsing keywords with trailing spaices

It's still posible trigger the bug with the current stable release. 

My attachment fix the bug in a very simple way. If mono developers are interested in the patch they can use it.
Comment 3 joe 2014-11-20 08:41:27 UTC
This seems to still be a problem in the latest release.  For example

{"test":true } will fail due to the whitespace following the boolean.  When will this patch be added to the main source?
Comment 4 Rodrigo Kumpera 2015-04-14 12:38:43 UTC
Hey Marcos,

Could you review & merge this fix?
Comment 5 marcos.henrich 2015-04-16 14:20:54 UTC
Hi Alex, Salvador, Joe,

Thank you for the bug report.

The pull request for this issue can be found in the link below.
Comment 6 marcos.henrich 2015-04-19 09:47:49 UTC
Fixed in mono master 3fa9d4d5c920ef4c67a99240d6f23bb1340159b5.
Comment 7 mz 2015-08-05 03:44:35 UTC
Any chance this fix would be included in am acutal released version?
Currently it's only available in master.
Comment 8 marcos.henrich 2015-08-10 12:23:30 UTC
Hi mz,

This will be included on mono 4.2 release.