Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to auto-generate a C# class file from a JSON string [closed]

Five options:

  • Use the free jsonutils web tool without installing anything.

  • If you have Web Essentials in Visual Studio, use Edit > Paste special > paste JSON as class.

  • Use the free jsonclassgenerator.exe

  • The web tool app.quicktype.io does not require installing anything.

  • The web tool json2csharp also does not require installing anything.

Pros and Cons:

  • jsonclassgenerator converts to PascalCase but the others do not.

  • app.quicktype.io has some logic to recognize dictionaries and handle JSON properties whose names are invalid c# identifiers.


Visual Studio 2012 (with ASP.NET and Web Tools 2012.2 RC installed) supports this natively.

Visual Studio 2013 onwards have this built-in.

Visual Studio Paste JSON as Classes screenshot (Image courtesy: robert.muehsig)


If you install Web Essentials into Visual studio you can go to Edit => Past special => paste JSON as class.

That is probably the easiest there is.

Web Essentials: http://vswebessentials.com/