A Cool New ‘Paste JSON As Classes’ Feature in ASP.NET Web Tools 2012.2 RC

January 26, 2013

Great news for Web developers, With ASP.NET and Web Tools 2012.2 RC installed, you now have a great and easy tool for converting your JSON objects into C# or VB.NET classes.

This feature uses Newtonsoft JSON parser to parse JSON text from clipboard. Once Newtonsoft JSON parser validates the clipboard data as valid JSON, then it will be converted into C# or VB.NET class depending on the selected file type.

Here’s a simple example:

A) Copy to clipboard your JSON object.

{

    "link": "http://www.microsoft.com/Surface/en-US",

    "virtual": "Virtual Keyboard",

    "partial": " The magnesium panels are finished with partial vapor deposition",

    "Price": 499.99,

    "title": "Microsoft Surface",

    "Like": true,

    "cdDrive":null,

}

B) In VS2012, open edit menu, choose ‘Past Special’ and click on ‘Past JSON As Classes’.

The result:

public class Rootobject

{

    public string link { get; set; }

    public string _virtual { get; set; }

    public string partial { get; set; }

    public float Price { get; set; }

    public string title { get; set; }

    public bool Like { get; set; }

    public object cdDrive { get; set; }

}

Of course it also supports more complex objects like Multi-Dimensional Arrays etc..

Reference:

http://blogs.msdn.com/b/webdev/archive/2012/12/18/paste-json-as-classes-in-asp-net-and-web-tools-2012-2-rc.aspx

Hope you find this article handy.

Add comment
facebook linkedin twitter email

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

*