Home » Tutorials » C# » Convert DataTable to JSON in C#

Convert DataTable to JSON in C#

Convert DataTable to List C#
Find out all tables without indexes in Sql Server

Convert DataTable to JSON in C#

We have already explained Convert DataTable to List C#, Is Application running already in WPFExtension Method in C#Reflection Introduction c#Insert data into Database table using SQLBulkCopy class in C#as keyword C#, Import/Upload Excel file in asp.net with C#The Microsoft Jet database engine cannot open the file. It is already opened exclusively by another user,   Call method after specific time interval C#Alert from code behind asp.net,required field validator in asp.net,Difference between RegisterClientScriptBlock and RegisterStartupScript asp.netDifference between ref and out parameters.

Today we will look “How to convert DataTable to JSON in C#!!!”

There are 3 different ways to convert DataTable to JSON in C#:

  1. Using StringBuilder
  2. Using JavaScriptSerializer
  3. Using Newtonsoft.

Lets say we have below DataTable available with us


Sample JSON string would be as below:

1. Using StringBuilder

Let try to build JSON string from DataTable using StringBuilder. Refer below code snippet:


2. Using JavaScriptSerializer

Add using System.Web.Script.Serialization;  namespace.


3. Newtonsoft

Download Newtonsoft dll from  Newtonsoft Download Link.

You can also download Convert DataTable To JSON

Thanks folks for reading my post and kindly leave your feedback.


Hello friends, My self Dhruv Sheth, I have more than 6 years of Industrial experience as a Software Developer. In my career I got chance to work with asp.net, c#,Web API, JavaScript, JQuery, WPF, WCF , Windows Application, PostScript, vb.net, GhostScript etc. So I have decided to share my knowledge with everyone and finally I have come up with TechnoThirsty.

Leave a Reply

Your email address will not be published. Required fields are marked *


Time limit is exhausted. Please reload CAPTCHA.

The content is copyrighted to technothirsty.com and may not be reproduced on other websites without permission from the owner.You may contact us using the information below.