Converting JSON to C# Classes: A Comparison of Visual Studio and ChatGPT Methods

Noel Tiangco
3 min readNov 3, 2023

As a C# developer working with external APIs, it’s common to need to translate JSON strings into C# classes. This task can be mundane and time-consuming, but thankfully, tools exist to automate the process. I recall the moment of revelation when I first stumbled upon the “Paste JSON as Classes” feature in Visual Studio a few years ago, despite it being around since at least VS 2012.

For those unfamiliar, Visual Studio has a neat feature where you simply copy a JSON string and use the menu option “Edit > Paste Special > JSON as Classes” in an empty class file. Unfortunately, this option isn’t available in the context menu that appears when you right-click (which is probably why I didn’t discover this right away). Once executed, Visual Studio generates the C# class structure from the JSON schema.

Consider the JSON snippet below:

{
“Name”: “Noel”,
“Interests”: [“Coding”, “Board games”],
“Siblings”: 5,
“WeightLbs”: 123.45
}

Using the feature in Visual Studio, this gets transformed into:

public class Rootobject
{
public string Name { get; set; }
public string[] Interests { get; set; }
public int Siblings { get; set; }
public float WeightLbs { get; set; }
}

--

--

Noel Tiangco

25+ years as professional developer | .NET specialist | Sharer and Learner