Skip to content

Instantly share code, notes, and snippets.

@JonCanning
Created August 13, 2021 16:20
Show Gist options
  • Save JonCanning/c8de46db00b031195c58447ffd10a62c to your computer and use it in GitHub Desktop.
Save JonCanning/c8de46db00b031195c58447ffd10a62c to your computer and use it in GitHub Desktop.
Sensible json defaults
module Json
open Microsoft.FSharpLu.Json
open Newtonsoft.Json
open Newtonsoft.Json.Serialization
open Newtonsoft.Json.Converters
let private compactJsonSerializerSettings =
let settings = Compact.TupleAsArraySettings.settings
StringEnumConverter(CamelCaseText = true)
|> settings.Converters.Add
settings.ContractResolver <- CamelCasePropertyNamesContractResolver()
settings.NullValueHandling <- NullValueHandling.Ignore
settings.MissingMemberHandling <- MissingMemberHandling.Ignore
JsonConvert.DefaultSettings <- fun () -> settings
settings
let serialize o =
JsonConvert.SerializeObject(o, compactJsonSerializerSettings)
let deserialize<'T> json =
JsonConvert.DeserializeObject<'T>(json, compactJsonSerializerSettings)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment