title: Update appsetting.json in run time in .netcore
body: <p>I have this appsetting json file :</p>
  <pre><code>&quot;RavenOptions&quot;: {
      &quot;PublicUrl&quot;: &quot;http://127.0.0.1:61570&quot;,
      &quot;PublicDbName&quot;: &quot;TestHostBuilder_ctor_1&quot;,
      &quot;TseDbName&quot;: &quot;TestHostBuilder_ctor_1&quot;,
      &quot;IsHttps&quot;: &quot;false&quot;,
      &quot;CertificateDirectory&quot;: &quot;&quot;,
      &quot;ShardUrls&quot;: [
        &quot;http://127.0.0.1:61570&quot;,
        &quot;http://127.0.0.1:61570&quot;,
        &quot;http://127.0.0.1:61570&quot;,
        &quot;http://127.0.0.1:61570&quot;
      ]
    }
  </code></pre>
  <p>I need to update the values of the file in runtime .I am using this function :</p>
  <pre><code> public static void AddOrUpdateAppSetting&lt;T&gt;(string key, T value)
      {
          try
          {
              var filePath = Path.Combine(AppContext.BaseDirectory, &quot;appSettingTest.json&quot;);
              string json = File.ReadAllText(filePath);
              dynamic jsonObj = Newtonsoft.Json.JsonConvert.DeserializeObject(json);
  
              var sectionPath = key.Split(&quot;:&quot;)[0];
  
              if (!string.IsNullOrEmpty(sectionPath))
              {
                  var keyPath = key.Split(&quot;:&quot;)[1];
                  jsonObj[sectionPath][keyPath] = value;
              }
              else
              {
                  jsonObj[sectionPath] = value; // if no sectionpath just set the value
              }
  
              string output = Newtonsoft.Json.JsonConvert.SerializeObject(jsonObj, Newtonsoft.Json.Formatting.Indented);
              File.WriteAllText(filePath, output);
          }
          catch (ConfigurationErrorsException)
          {
              Console.WriteLine(&quot;Error writing app settings&quot;);
          }
      }
  </code></pre>
  <p>this function works fine but the problem is when I want to update the values of <code>sharedurls</code> (this is an array) the result is like this :</p>
  <p><a href="https://i.stack.imgur.com/GrSsH.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GrSsH.png" alt="enter image description here" /></a></p>
  <p>All records are in one row .But I need tho be like this :</p>
  <p><a href="https://i.stack.imgur.com/pORy4.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pORy4.png" alt="enter image description here" /></a></p>
  <p>every records is one row.
  Here is my update code :</p>
  <pre><code>string serverAddress = &quot;\&quot;&quot;+documentStore.Identifier.Split(&quot;(&quot;).First()+&quot;\&quot;&quot;;
          Appset.AddOrUpdateAppSetting(&quot;RavenOptions:PublicDbName&quot;, documentStore.Database);
          Appset.AddOrUpdateAppSetting(&quot;RavenOptions:PublicUrl&quot;, documentStore.Identifier.Split(&quot;(&quot;).First());
          Appset.AddOrUpdateAppSetting(&quot;RavenOptions:ShardUrls&quot;,&quot;[&quot;+String.Join(&quot;,&quot;, Enumerable.Repeat(serverAddress, 4).ToArray())+&quot;]&quot;);
  </code></pre>