-1

I am new to C# regex. I have the following JSON string. I want to remove quotes around "true" or "false", whenever they occur, within this string so that these values become JSON boolean types instead of strings.

    "{"email":"johnq@gmail.com","firstName":"John","lastName":"Quinton","moreThanFiveYears":"false","member":"true","insertDate":"2019-04-14 17:28:40"}"

"{"email":"johnq@gmail.com","firstName":"John","lastName":"Quinton","moreThanFiveYears":false,"member":true,"insertDate":"2019-04-14 17:28:40"}"

The first string is the one I currently have. I want to change it to the second one. I know how to remove quotes from the start and end of a string, but not sure how to remove from words within a longer string and moreover the words in question (true/false) can occur at multiple times.

Massey
  • 1,099
  • 3
  • 24
  • 50
  • 3
    Why would you want to do this? A JSON deserialiser (e.g. JSON.Net) won't care about the quotes if you use a concrete class. – DavidG Apr 15 '19 at 02:30
  • The problem is that the json is obtained from a SQL server 2008 query through string concatenation – Massey Apr 15 '19 at 02:59
  • Why does it matter how it was created? All you should care about is how it's going to be consumed. – DavidG Apr 15 '19 at 03:09
  • Hi David, I have to send this JSON to the third party web api. When I send "true" or "false", I get a 400 bad request error. If I send these two values without the quotes, then I get 200 OK response. – Massey Apr 15 '19 at 03:27

1 Answers1

0

May be you get some idea from this.

(?<=false|true)"|"(?=true|false)

Demo: https://regexr.com/4c94f

Abimanyu
  • 495
  • 2
  • 13