# Calling Nakama.TinyJson.JsonWriter.ToJson on an object with a DateTime will crash

**URL:** <https://forum.heroiclabs.com/t/calling-nakama-tinyjson-jsonwriter-tojson-on-an-object-with-a-datetime-will-crash/212>\
**Category:** Local Setup\
**Created:** [September 17, 2019, 8:20pm UTC](https://forum.heroiclabs.com/t/calling-nakama-tinyjson-jsonwriter-tojson-on-an-object-with-a-datetime-will-crash/212 "2019-09-17T20:20:29Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![bbi-barrymccallum](https://avatars.discourse-cdn.com/v4/letter/b/34f0e0/32.png) [@bbi-barrymccallum](https://forum.heroiclabs.com/u/bbi-barrymccallum)\
**Post date:** [September 17, 2019, 8:20pm UTC](https://forum.heroiclabs.com/t/calling-nakama-tinyjson-jsonwriter-tojson-on-an-object-with-a-datetime-will-crash/212/1 "2019-09-17T20:20:29Z")

</div>

string f = Nakama.TinyJson.JsonWriter.ToJson(DateTime.UtcNow);

This call with crash with:  
An unhandled exception of type ‘System.StackOverflowException’ occurred in mscorlib.dll.

Ran into this while I was about to add some objects to the Nakama collection storage that had DateTime properties in them. I could use a Newtonsoft json parser to convert these instead but if I didn’t have to add another dependency that would be nice.

---

<div class="post-metadata">

**Author:** ![zyro](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/zyro/32/14_2.png) [@zyro](https://forum.heroiclabs.com/u/zyro)\
**Post date:** [September 19, 2019, 12:12pm UTC](https://forum.heroiclabs.com/t/calling-nakama-tinyjson-jsonwriter-tojson-on-an-object-with-a-datetime-will-crash/212/2 "2019-09-19T12:12:04Z")

</div>

TinyJson is intended to be a compact and resource-efficient JSON encoder/decoder so it doesn’t quite handle every type.

It’s probably easiest to just convert your DateTime type to a string notation like ISO 8601 or an integer representing UTC seconds/milliseconds before passing it to be encoded as JSON.
