0

I have a JSON.stringify(Array) that looks like

"[{\"Status\":\"Active\",\"DBID\":\"SB\",\"ID\":33},{\"Status\":\"Active\",\"DBID\":\"SB\",\"ID\":12}]"

And this is sent via an AXIOS command to a .NET Web API. The .NET Web API sends the string to a MS SQL stored proc.

My question is how can I convert the string back into standard JSON so I can use it in a stored proc. If I remove the leading and trailing double quotes and remove all of the backslashes ("") so that it looks like

'[{"Status":"Active","DBID":"SB","ID":33},{"Status":"Active","DBID":"SB","ID":12}]'

The stored proc runs fine using something like:

SELECT * FROM OPENJSON(@json)

If I run it with the backslashes I get

JSON text is not properly formatted. Unexpected character '' is found at position 2.

Should it be converted in the .NET Web API or the stored proc?

In the stored proc if I

set @json = replace(@json,'\','')
set @json = replace(@json,'"[','[')
set @json = replace(@json,']"',']')

But I was hoping for a cleaner solution.

Phil
  • 157,677
  • 23
  • 242
  • 245
Bill
  • 1,423
  • 2
  • 27
  • 51
  • Does this answer your question? [Replacing escape characters from JSON](https://stackoverflow.com/questions/16692371/replacing-escape-characters-from-json) – tymtam Apr 20 '21 at 23:12
  • Sounds like you might be double-encoding the string. Please show how you're creating and sending the JSON to your backend? – Phil Apr 20 '21 at 23:29
  • 1
    Your right. I did have it double-encoded. Once when I created the data from the array and once when I sent it in the AXIOS call. I took that out and it's working fine. I didn't plan on doing it twice, but it was there. THANK YOU – Bill Apr 21 '21 at 10:50

0 Answers0