I am trying to send regex string in JSON body of my http request like this
{
"pattern":"\b\d{8}\b"
}
But I get a 400 response from the server
Unexpected token d in JSON at position xxx
If I try to escape the "\" in the JSON body like
{
"pattern":"\b\\d{8}\b"
}
The server doesn't throw any error but the request body received in the server end is incorrect
Expectation:
{
"pattern":"\b\d{8}\b"
}
Result:
{
"pattern":"\b\\d{8}\b"
}
Any inputs or references will be helpful.
Thanks,
Did you trying sending as string First in requesting side
JSON.stringify({ "pattern":"\b\\d{8}\b" })
in controller side
public class myregex
{
public string pattern{ get; set; }
}
JsonConvert.DeserializeObject<myregex>(json)