Search code examples
c#jsonapp-config

How to add a json string as a app setting value in config file


I have a requirement whereby I need to fetch a set of jsons before making a API call. I am planning to add these json strings in app.config as shown below

 <add key="Jsons" value="{""Id"":""25"",""Name"":""Value-1""}"/>

However adding this results in a compilation error "Missing whitespace" at the start of the value. Please let me know if i am missing something. I dont want to create a separate text file to read jsons from. Thats why i decided to use app.config itself


Solution

  • Your quotes are not correctly formatted. Can you try this:

    <add key="Jsons" value='{"Id":"25","Name":"Value-1"}'/>