RugabaRj
RugabaRj
CC#
Created by VoidPointer on 11/8/2024 in #help
✅ How to specify camel case for all response properties with Newtonsoft
c#
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;

var settings = new JsonSerializerSettings
{
ContractResolver = new CamelCasePropertyNamesContractResolver(),
Formatting = Formatting.Indented
};

var obj = new
{
FirstName = "John",
LastName = "Doe"
};

string json = JsonConvert.SerializeObject(obj, settings);
Console.WriteLine(json);
c#
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;

var settings = new JsonSerializerSettings
{
ContractResolver = new CamelCasePropertyNamesContractResolver(),
Formatting = Formatting.Indented
};

var obj = new
{
FirstName = "John",
LastName = "Doe"
};

string json = JsonConvert.SerializeObject(obj, settings);
Console.WriteLine(json);
11 replies