Powered By Blogger

Sunday, January 08, 2023

Microsoft Visual Studio | Generate Class from JSON or XML

Microsoft Visual Studio | Generate Class from JSON or XML

I found an useful feature in visual studio to generate class from JSON or XML. In Visual Studio, you can copy JSON or XML text and then paste the text as classes in C#/VB.Net code file using following steps:
  1. Copy Your JSON: example:
    {
    "PersonId": 1,
    "GoalId": 111,
    "ActivityId": 1111,
    "Task": {
                  "Name": "Task-1",
                  "Description": "Task-1 desc",
                  "ActivityScope": 5,
                  "ActivityType": 1,
                  "isCustomized": true
               }
    }
  2. Select Edit > Paste Special and choose Paste JSON As Class:


    it will create class like this for the above JSON:



  3. Same can be done using XML Paste.

No comments:

Post a Comment