Nicely done "Johann Medina", but you forgot to explain a little bit your solution in order people can understand better the idea. I have done it the same way, but here it's the full explanation in order to use it this way...
appsetting.JSON example:
{ "Email": { "Host": "smtp.office365.com", "Port": "587", "From": "[email protected]", "Username": "[email protected]", "Password": "IsAAbbUaa22YTHayTJKv44Zfl18BClvpAC33Dn5p4s=" } }
POCO class example:
namespace AppSettingsTest { public class AppSettings { public Email Email { get; set; } } public class Email { public string Host { get; set; } public int Port { get; set; } public string From { get; set; } public string Username { get; set; } public string Password { get; set; } } }
Getting appsetting.JSON content example:
using (var reader = new StreamReader(Directory.GetCurrentDirectory() + "/appsettings.json")) { var appSettings = JsonConvert.DeserializeObject<AppSettings>(reader.ReadToEnd()); }
NOTE: Just make sure to set "Copy always" in the property option "Copy to Output Directory" to the JSON file.
Happy Coding!