7

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

3
  • If I dont use "" i get multiple errors Commented Feb 11, 2016 at 4:51
  • Should be formated like {"Id":"25", "Name":"Value-1"} Commented Feb 11, 2016 at 4:54
  • That gives formating errors Commented Feb 11, 2016 at 4:55

3 Answers 3

13

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

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

Sign up to request clarification or add additional context in comments.

5 Comments

Wow, that looks a lot like my comment??
@Fergus Why the down vote? I didn't saw your comment, and when I looked at it now, mine was more complete :)
@ShaijuJanardhanan, great, don't forget to mark it as the answer if it is :)
@Fergus but i couldnt figure out the issue from your answer since i had tried with proper formatting too. The single quote was what i was not using
Awesome, that's the beauty of SO.
2

An app.config is still XML! You need to use the XML escape sequence for quotes.

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

1 Comment

That looks a lot verbose. The accepted answer actually works
0

I see two choices here:

  1. Use "\" to escape:

      <add key="Jsons" value="{\"Id\":\"25\",\"Name\":\"Value-1\"}"/>
    
  2. Use single quote:

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

2 Comments

Though many parsers may allow it, using single quotes in JSON is technically invalid.
It is not a valid JSON

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.