Skip to content

Instantly share code, notes, and snippets.

@rprakashg
Created March 1, 2015 03:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rprakashg/681690760c0baa36fdaf to your computer and use it in GitHub Desktop.
Save rprakashg/681690760c0baa36fdaf to your computer and use it in GitHub Desktop.
ToJson extension methods for serializing objects to json uses CamelCasePropertyNamesContractResolver so serialized string will follow camel casing
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
public static class JsonExtensionMethods
{
public static String ToJson(this object model)
{
JsonSerializerSettings settings = new JsonSerializerSettings
{
NullValueHandling = NullValueHandling.Ignore,
ContractResolver = new CamelCasePropertyNamesContractResolver(),
};
return JsonConvert.SerializeObject(model, Formatting.Indented, settings);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment