{"id":21477569,"url":"https://github.com/adamfoneil/jsonsettings","last_synced_at":"2025-07-17T04:36:25.429Z","repository":{"id":38100636,"uuid":"139843693","full_name":"adamfoneil/JsonSettings","owner":"adamfoneil","description":"Base class for saving, encrypting, and loading application settings in a Json file","archived":false,"fork":false,"pushed_at":"2024-07-03T17:38:50.000Z","size":92,"stargazers_count":11,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-11-13T00:13:09.070Z","etag":null,"topics":["dpapi","json-settings"],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/adamfoneil.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-07-05T12:05:03.000Z","updated_at":"2024-11-05T21:05:08.000Z","dependencies_parsed_at":"2022-08-18T13:01:16.783Z","dependency_job_id":null,"html_url":"https://github.com/adamfoneil/JsonSettings","commit_stats":null,"previous_names":["adamosoftware/jsonsettings"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adamfoneil%2FJsonSettings","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adamfoneil%2FJsonSettings/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adamfoneil%2FJsonSettings/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adamfoneil%2FJsonSettings/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/adamfoneil","download_url":"https://codeload.github.com/adamfoneil/JsonSettings/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":226033242,"owners_count":17563126,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dpapi","json-settings"],"created_at":"2024-11-23T11:14:19.677Z","updated_at":"2024-11-23T11:14:20.376Z","avatar_url":"https://github.com/adamfoneil.png","language":"C#","readme":"[![Build status](https://ci.appveyor.com/api/projects/status/7rtpqxwoasjes1id?svg=true)](https://ci.appveyor.com/project/adamosoftware/jsonsettings)\n[![Nuget](https://img.shields.io/nuget/v/JsonSettings.Library)](https://www.nuget.org/packages/JsonSettings.Library/)\n\nThis is sort of an update of my [AoOptions](https://github.com/adamosoftware/AoOptions) project, moving it from XML to Json, and removing the WinForms dependency. It was also important that I support a DPAPI encryption on properties, since the intended use case for this is to store sensitive things like database connection strings and other credentials. More info about DPAPI is [here](https://docs.microsoft.com/en-us/dotnet/standard/security/how-to-use-data-protection).\n\nNuget package: **JsonSettings.Library**\n\nNote, as of 1/21/19, version 1.0.8 replaces the package **AoJsonSettings** in order to target .NET Standard 2.0.\n\n## How to Use\n\n1. Create a class for your app settings based on [SettingsBase](https://github.com/adamosoftware/JsonSettings/blob/master/JsonSettings.Library/SettingsBase.cs) abstract class and implement the [Filename](https://github.com/adamosoftware/JsonSettings/blob/master/JsonSettings.Library/SettingsBase.cs#L12) property.\n\n2. If you need to encrypt a string property, add the [[JsonProtect]](https://github.com/adamosoftware/JsonSettings/blob/master/JsonSettings.Library/JsonProtectAttribute.cs) attribute to the property. Props to this [SO answer](https://stackoverflow.com/a/29240043/2023653) from [Brian Rogers](https://stackoverflow.com/users/10263/brian-rogers) on implementing the custom attribute that does this. \n\n3. Instantiate your settings class with `JsonSettingsBase.Load\u003cT\u003e` where `T` is your settings type.\n\n4. Use the `Save` method to persist any modified settings to disk.\n\n## Examples\n\n```csharp\nvar settings = SettingsBase.Load\u003cMySettings\u003e();\n\n// when app closing or on some other event:\nsettings.Save();\n```\nEncrypted property example:\n```csharp\npublic class AppSettings : SettingsBase\n{\n    public override string Filename =\u003e BuildPath(Environment.SpecialFolder.LocalApplicationData, \"AppSettings.json\");\n    \n    public string Greeting { get; set; } = \"hello\";\n\n    [JsonProtect(DataProtectionScope.CurrentUser)]\n    public string SensitiveValue { get; set; }\n}\n```\n\n## A Simpler Use\n\nIf you don't need the built-in settings file handling logic, you can use the [JsonFile](https://github.com/adamosoftware/JsonSettings/blob/master/JsonSettings.Library/JsonFile.cs) static class with its `Load`, `Save` (and `LoadAsync`, `SaveAsync`) methods to make it easy to save any json data to a file. The [JsonProtect] attribute still works in this usage.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadamfoneil%2Fjsonsettings","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fadamfoneil%2Fjsonsettings","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadamfoneil%2Fjsonsettings/lists"}