I have some data in form of objects, inside a list object. Now I want to serialize this data to JSON. For this I’m (currently) using JSON.NET. My problem is that with
JsonConvert.SerializeObject(list, ...)
I seem to only have the option to either indent the whole thing, aka every key/value, or not indent at all.
{"Variable1":1,"Variable2":"2"},{"Variable1":1,"Variable2":"2"},...
or
{
"Variable1": 1,
"Variable2": "2"
},
{
"Variable1": 1,
"Variable2": "2"
},
...
I’d like to get this:
{ "Variable1": 1, "Variable2": "2" },
{ "Variable1": 1, "Variable2": "2" },
but without having to explicitly writing every key/value myself (JsonTextWriter or manually). I just want to pass the list and get the above. Is this somehow possible? At the moment I’m serializing every object separate, by going through the list, and running some replaces, regex replaces, and similar, to get the desired output, depending on the input list. Is there an easier way to do this, without writing your own serialization method?
hello i found something that my help you to start your special formatter
i translated it from javascript to c# from here: https://github.com/umbrae/jsonlintdotcom/blob/master/c/js/jsl.format.js
it add whitespaces to json string without them.
i think you can modify this formatter to your own needs.