I simply want the JSON.net serializer to write out JSON objects (to file), one object per line but instead it just appends everything on the same top line.
The samples provided are indented for clarity, but the default behavior is to write the resulting JSON string without any unnecessary whitespace. You can override this behavior like this:
jw.Formatting = Formatting.Indented;
jw.WriteStartObject();
...
Further Reading
To ensure that each entry is appended to a new line, you could simply write a new line character after you've written your JSON object, like this:
...
jw.WriteEndObject();
jw.WriteRaw("\n");
Or by calling WriteLine on the underlying TextWriter
, though that would need to be done outside of this method.
Figured it out, though not sure if there's a cleaner way. I added a
jw.WriteWhitespace(Environment.NewLine);
at the end. Now everything looks good:
{"TimeStamp":"2014-03-10T15:04:27.0128185",...}
{"TimeStamp":"2014-03-10T15:04:27.0128185",...}
...