Quickly Generate C# Classes from JSON Responses

Play Quickly Generate C# Classes from JSON Responses
Sign in to queue


This short video will show the developer how to use the Web Essentials Visual Studio Plugin, and a quick tip to quickly generate typed C# classes for working with JSON Responses.  This is very handy if your application makes calls to REST API's that return JSON responses.

[00:48] - Simple HTTP Client call to REST API

[01:01] - Generate C# file for declaring classes

[01:40] - Inspect JSON Response in Debugger

[01:56] - Paste as JSON Classes with web essentials

[02:34] - Using the new JSON Class in the code




Download this episode

Download captions

The Discussion

  • User profile image

    Thank you. Very cool.  How do you get the reference counts to display in Visual Studio like you have in the demo?

  • User profile image
    It is part of update 2 or 3 of visual studio 2013. Quite a lot of funky thongs have been added recently.
  • User profile image

    Just what I desperately needed. Perfect!! I'm working on a project that requires making a ton of remote API calls. Now I don't have to manually create all the c# classes. I just quickly generated all the classes following this video. Infinite gratitude to Bret Bentzinger and Channel 9 for sharing this video.

  • User profile image

    @Niner705639:Which reference count?  I am just expanding the obj local variable.

  • User profile image

    @Fission:The plugin is for Visual Studio Update 3

  • User profile image

    Nice tool!  It would be good to expand to select a json file and convert to classes.  Maybe some type of wizard.

  • User profile image

    @shaggygi:That would be cool.  Good idea!

  • User profile image

    @BretBentzinger: I believe @Niner705639 was referring to the Code Lens reference counting on the methods and classes.

  • User profile image

    Good tool. When dealing with JSON I find that the conversion tool at <a href="https://json-csv.com">json-csv.com</a> provides a nice quick way to view the data without having to code.

  • User profile image

    I got that link wrong above...it's https://json-csv.com

  • User profile image

    This is great! Very helpful!

  • User profile image
    Richard Hill

    Hi, I seldom make the time to post on these forums as I am actually busy working on code. I saw this post and thought it to be a VERY useful utility that would save me some time to potentially post on forums and perhaps give a little back to the community.

    I'm afraid thats not to be.

    This 'tool' has failed to work for me. I suggest that the creators of it perform some due diligence on their work and 'test' their code.

    I also suggest that Channel9 take this video down as it puts them in a poor light.


  • User profile image

    @Richard Hill: it would be interesting to see why this tool is failing you. If there are any bugs I would suggest you raise them accordingly rather than lambasting the developer(s) who put effort in creating this. Or better yet, you could write your own VS plugin that can do this better and help the community, as you say you like to do. 

    In the meantime, please note that in VS2013 you can achieve the same thing without the need to use WebEssentials. Copy your Json from the source then in VS --> Menu --> Edit --> Paste Special --> Paste Json as Classes/Paste Xml as Classes. Demo here.

    I hope you find this useful and thanks to @bret for his excellent work

  • User profile image

    Thanks!  This saved me a bunch of time.

Add Your 2 Cents