Skip to content

Instantly share code, notes, and snippets.

@ninjarobot
Created January 20, 2021 23:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ninjarobot/e71643ab4889cf9c5b133d62bba4647f to your computer and use it in GitHub Desktop.
Save ninjarobot/e71643ab4889cf9c5b133d62bba4647f to your computer and use it in GitHub Desktop.
Load a configuration source from a JSON string in F#
open Microsoft.Extensions.Configuration
/// Builds a configuration source from raw JSON.
let configSourceFromJson (json:string) : IConfigurationSource =
{ new IConfigurationSource with
member this.Build (builder:IConfigurationBuilder) =
{ new ConfigurationProvider() with
member this.Load() =
this.Data <- Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string,string>> json
} :> IConfigurationProvider
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment