Is it possible to convert JSON data in C#?

dapoole

New member
Joined
Jun 29, 2017
Messages
3
Programming Experience
Beginner
Hi there,

I am DBA with zero C# programming experience however I would like to ask all C# programmers out there how they would handle large JSON data. Currently I have a very slow query when trying to convert filestream NVARBINARY(MAX) stored JSON data into NVARCHAR(MAX) from within SQL Server, such as:


SELECT ID
,
JSONDATA
,
(CONVERT(NVARCHAR(MAX),JSONDATA)) AS 'JSON'
FROM
Forms

Is there a method in C# where this (CONVERT(NVARCHAR(MAX),JSONDATA)) conversion can be taken out of the database to be performed in the application layer?
When (CONVERT(NVARCHAR(MAX),JSONDATA)) is removed from the query it returns extremely fast. With (CONVERT(NVARCHAR(MAX),JSONDATA)) included it takes many minutes.

TIA
 
Thanks. Anyone know what the performance comparison is between doing a conversion from within the database engine to using C# at the application layer is? Which would be quicker?

This:

SELECT CONVERT(nvarchar(max),JSONDATA) FROM Forms

Or this:


using(var command =newSqlCommand(connection))
{
command
.CommandText=@"SELECT JSONDATA FROM Forms";
command
.Open();
byteArray
= command.ExecuteScalar()asbyte[];
}

var result =System.Text.Encoding.UTF8.GetString(byteArray);
 

Latest posts

Back
Top Bottom