Click here to Skip to main content
12,555,044 members (55,817 online)
Click here to Skip to main content
Add your own
alternative version


8 bookmarked

.NET DataTable To JSON Format Conversion Tool for WCFServices

, 4 Nov 2013 CPOL
Rate this:
Please Sign up or sign in to vote.
A .NET v4 Library for converting DataTable row(s) to JSON String for WCFServices


The attached plugin is a useful plugin put together to help with converting .NET DataTables to JSON formatted strings, that can be passed through WCFServices without compromising the plumbing.
I put it together because I have developed a lot of custom .NET libraries for use with WCFServices and given the JSON footprint and mobile access to data. I just wanted to have a solution I can easily integrate into my existing applications without having to build new ones.


As I mentioned in the introduction, I am mostly a Windows platform developer, and have a deep love for WCFServices. However, with the proliferation of mobile devices and applications, data consumption needs to be treated with great care by developers. When it comes to transmission format, I recently got wind of JSON and how it seems to be a de-facto mobile data transmission format and have put together a small library (download attached) to help those like myself.

Using the Code

.NET Platform: 4.0

In Visual Studio --> Solution Explorer

  1. Right click on your project and select Add Reference
  2. Select Browse tab and navigate to the location of your decompressed file
  3. Select Munhemba.DataTableToJSON.dll

For C#, do the following:

Add [using Munhemba.DataTableToJSON;]

Within your code, declare the library as follows:

public string GetTableRowsJSON()
    string jsonData = null;
    using ([yourDataSetName] [yourDataSet_Alias] = new [yourDataSetName]())
        [yourTableAdapterAlias] = new [yourDataSetName]TableAdapters.[YourTableNameAdapter]();
        Munhemba.DataTableToJSON dtToJSON = 
        	new Munhemba.DataTableToJSON([yourDataSetName].[YourTableName]);
        jsonData = dtToJSON.outputString;
        return jsonData;

You may expose the GetTableToRows function through a WCFService the normal way and still get to benefit from the plumbing that comes along with WCF, such as WSHttpBinding, etc.

Happy coding.

Points of Interest

I believe that applications and databases can no longer in fact, should not exist in isolation. WCF provides a tested platform for CRUD on a variety of databases, personally having worked with MSSQL Server, MySQL, ORACLE, and having integrated some of them, I find the JSON format becoming a versatile companion to WCF because of the lightness (message size) of the data transmitted, then again the good relationship it has with JQuery makes it all worth the while to look into and consider.


  • First article posted 03 November 2013


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Software Developer
South Africa South Africa
My IT Career began in 1996 as I was studying to become a Chartered Accountant.

Between 1998 to Date I have worked as a Computer Technician, IT Manager, Tutor and to my present position of Developer in a company I co-own with a colleague based in Johannesburg South Africa.

We do Web Hosting, design and development, and have only recently added Dot.Net Enterprise Application development to the business portfolio of Services.

You may also be interested in...


Comments and Discussions

QuestionQuestion Pin
Member 104478645-Dec-13 10:28
memberMember 104478645-Dec-13 10:28 
AnswerRe: Question Pin
SimbarasheM5-Dec-13 23:34
memberSimbarasheM5-Dec-13 23:34 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.161021.1 | Last Updated 4 Nov 2013
Article Copyright 2013 by SimbarasheM
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid