JSON format format automatically changed from SQL Server to ASP.NET environment, why?

Toni Sharp 21 Reputation points
2020-10-29T15:21:23.1+00:00

I am experimenting with SQL Server 2016 For JSON AUTO clause. I created a stored procedure and when I view the data with in SQL Server I get something like
[{"TotalCount":72,"ClaimReason":"Def Merch"},{"TotalCount":320,"ClaimReason":"Price Correction"},{"TotalCount":47,"ClaimReason":"Dup Ship"}]

With in my ASP.NET website I created a method to call the above stored procedure and when I view the data it looks different, backslashes have been added to it.

object dtOpenClaims = spReports.OpenClaimCountsByClaimReason();

The format of the JSON changed to the following
[{\"TotalCount\":72,\"ClaimReason\":"\Def Merch\"}.....

Any ideas why?

Thanks,
Toni

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
13,629 questions
0 comments No comments
{count} votes

Accepted answer
  1. Viorel 116.6K Reputation points
    2020-10-29T15:30:50.023+00:00

    Probably the value is a string and Visual Studio shows it according to the rules of C# source code, where you must write \" in order to include the quotation mark inside a string.

    To display the contents directly, try adding dtOpenClaims,nq to Watch window during debugging.

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Toni Sharp 21 Reputation points
    2020-10-29T15:41:26.58+00:00

    Thank you, I will try that. We have a well worn path of getting data from SQL Server and within ASP.NET converting it to JSON, I just wanted to spend some time seeing if getting JSON data at the database level would be useful.

    Thanks,
    Toni

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.