Categories Microsoft .Net

Copy JSON/XML and Paste as Classes in Visual Studio

Copy your JSON/XML data and Paste it as Classes in Visual Studio

Copy the JSON response/data

{
    "MaterialID": 3,
    "CASNumber": "CAS0003",
    "MaterialTypeID": 1,
    "MaterialTypeName": "KSM",
    "UnitID": 1,
    "UnitName": "GMS",
    "Plant": "ML15",
    "MaterialNumber": "100P00A00367",
    "MaterialDescription": "HDPE OPEN TOP DRUM WITH LID CLAMP-10L",
    "IsActive": true,
    "LastUpdatedBy": "scmuser",
    "LastUpdatedOn": "13-Feb-2024, 20:53:53"
}
JSON

Open Visual Studio and click on any .cs file. Go to Edit->Paste Special menu

Click “Paste JSON AS Classes” option

public class Rootobject
{
    public int MaterialID { get; set; }
    public string CASNumber { get; set; }
    public int MaterialTypeID { get; set; }
    public string MaterialTypeName { get; set; }
    public int UnitID { get; set; }
    public string UnitName { get; set; }
    public string Plant { get; set; }
    public string MaterialNumber { get; set; }
    public string MaterialDescription { get; set; }
    public bool IsActive { get; set; }
    public string LastUpdatedBy { get; set; }
    public string LastUpdatedOn { get; set; }
}
C#

Next step, change your class name and use it.

Written By

With over a decade of experience in .NET technologies, SQL Server, and Agile methodologies, I am a Lead Software Developer at TEKsystems, where I design, develop, and support web-based applications for a leading market research company. I hold multiple certifications in LINQ, Entity Framework, and other .NET frameworks and tools, demonstrating my proficiency and commitment to continuous learning.

My core competencies include .NET Core, User Defined Functions, Stored Procedures, MVC, Web API, jQuery, and Bootstrap. I have successfully delivered several projects, such as a dashboard for analyzing consumer behavior, a portal for managing surveys and reports, and a tool for automating data quality checks. I am passionate about creating innovative and user-friendly solutions that help clients make informed business decisions. As part of a collaborative and agile team, I contribute to improving the quality, performance, and security of web applications, as well as providing technical support and documentation.

Email: codewithsivablog@gmail.com

More From Author

Leave a Reply

Your email address will not be published. Required fields are marked *