This project has moved and is read-only. For the latest updates, please go here.

Json.NET 5.x - .NET DateTime formatted as ISO 8601, but without trailing "Z"

Oct 3, 2013 at 2:52 PM
I've got a ASP.NET WEB API project with the current latest JSON.NET NuGet package (5.0.6) and I'm experiencing the following issue.

By default the JSON .NET Formatter is configured for ASP.NET Web API and it's also configured by default to use ISO 8601 date handling.

So, when I return a simple DTO object to a client, the JSON formatter outputs a date without the trailing "Z". E.g. "2009-03-21T08:30"

However, when I have a client post some JSON to the server, the model binder fails because parsing for the above value doesn't succeed, unless I add a trailing Z.

Inspecting the modelstate on the request, it shows an error with the following message:
"Could not convert string to DateTime: 2009-03-21T08:30. Path '', line 1, position 21."

As stated above, if I add a trailing Z to the JSON, the parsing succeeds and the correct date time value is provided to the model.

PS: Not sure if this issue relates (

Should the JSON formatter not append the "Z" or perhaps the parser support a date+time that has the "Z" omitted?

Am I doing something wrong?

Jan 6, 2014 at 9:25 PM
I have also hit this issue. Why was there no reply from the author to this?
Jan 25, 2014 at 12:52 AM
I am also having this problem. The documentation is out of date with the current way this works:

I can fix this by passing "new JsonSerializerSettings{DateTimeZoneHandling = DateTimeZoneHandling.Utc}" to the SerializeObject call. But this solution may not work for others.

Despite the minor annoyance, I still LOVE this library.