How to convert object to json with jsonconvert - without - key-quotations

Any library that expects JSON or actual JavaScript notation for creating objects (which is a superset of JSON) should work fine with quotes.

But if you really want to remove them, you can set JsonTextWriter.QuoteName to false. Doing this requires writing some code that JsonConvert.SerializeObject() uses by hand:

private static string SerializeWithoutQuote(object value)
{
    var serializer = JsonSerializer.Create(null);

    var stringWriter = new StringWriter();

    using (var jsonWriter = new JsonTextWriter(stringWriter))
    {
        jsonWriter.QuoteName = false;

        serializer.Serialize(jsonWriter, value);

        return stringWriter.ToString();
    }
}

Tags:

C#

Json