title: how to edit appsettings.json programmatically in winform on .net 6
body: <p>I am in process of replacing Settings.settings file with appsettings.json and this is what I have done</p>
  <pre><code>        [STAThread]
          static void Main()
          {
              ApplicationConfiguration.Initialize();
              using IHost host = CreateHostBuilder().Build();
              System.Windows.Forms.Application.Run(host.Services.GetRequiredService&lt;XtraMain&gt;());
          }
           static IHostBuilder CreateHostBuilder() =&gt;
           Host.CreateDefaultBuilder()
          .ConfigureAppConfiguration((context, builder) =&gt;
          {
              builder.AddJsonFile(&quot;apsettings.json&quot;, optional: true, reloadOnChange: true);
          })
          .ConfigureServices((context, services) =&gt;
          {
              services.AddScoped&lt;XtraMain&gt;();
              services.AddPersistenceServices(context.Configuration);
              services.Configure&lt;AppSettings&gt;(context.Configuration.GetSection(nameof(AppSettings)));
          });
  </code></pre>
  <p>And I add this AppSettings class to store data from AppSettings section in apsettings</p>
  <pre><code>    public class AppSettings
      {
          public  string Palette { get; set; }
          public  string ThemeName { get; set; } 
      }
  </code></pre>
  <p>and this my AppSettings</p>
  <pre><code>    {
      &quot;AppSettings&quot;: {
          &quot;Palette&quot;: &quot;Default&quot;,
          &quot;ThemeName&quot;: &quot;Office 2019 Colorful&quot;
      }
      }
  </code></pre>
  <p>and in my Main form</p>
  <pre><code>private readonly AppSettings settings;
  public XtraMain(IOptions&lt;AppSettings&gt; settings)
  {
      InitializeComponent();
      this.settings = settings.Value;
  }
  public void GetDataFromAppsettings()
  {
      UserLookAndFeel.Default.SkinName = settings.ThemeName;
      UserLookAndFeel.Default.SetSkinStyle(settings.ThemeName, settings.Palette);
  }
  public void SetAppsettings()
  {
    //modify appsettings.json Programmatically
  }
  </code></pre>
  <p>How can I modify appsettings.json Programmatically</p>