Home » Tutorials » ASP.NET » 4 ways to Convert JSON to DataTable in C# – asp.net

4 ways to Convert JSON to DataTable in C# – asp.net

Scheduler for multiple instances in C#
Add Google custom search in asp.net MVC website

4 ways to Convert JSON to DataTable in C# – asp.net

Problem: Sometime we do require to convert JSON to DataTable in C# Windows Application or Web application or website to display data using DataTable in GridView or DataGrid or other Server Control. I strongly recommend to read my other post as a reference before reading this post are Convert DataTable to JSON in C#Convert DataTable to List C#Extension Method in C#Extension Method with parameter in C#Convert List to XML in C# etc.


Here as a solution I will discuss three different ways from which we could Convert JSON to DataTable in C#.

1. Using Simple method

In this method we just split the string by using specific characters and tried to fetch data from JSON string. I have added full code snippet for your reference. Please refer and try to understand.

2. Using NewtonSoft.dll

In this method first of all we have to add Newtonsoft.dll. For this we have to add NeGet Package as shown below image:




After adding NeGet Package we have to add “using Newtonsoft.Json” and find below code for your reference.



3. Using NewtonSoft.dll by Linq

As shown in method-2 I have demonstrate how we could add NewtonSoft.dll. In this method we have used NewtonSoft’s  “using Newtonsoft.Json.Linq;” and we tried to convert Json into DataTable. Please find below code snippet for your reference.


4. Using Extension Method and Class

Finally in method-4 I have used Extension method and class to convert JSON string into DataTable. As you can see in below code snippet I have created Extension method named with “ToDataTable” and declared class named with “Employee”.


As an output of all programs we will get below image output as a DataTable:




Folks, I request you to test methods in your environment and use in live environment in terms of performance as well. I would be happy to hear from you guys. Let me know topics on which you want to know. Happy Coding!!!


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.