DEV Community


Automatic class creation for unmarshalling JSON

João Osório
Love to code although it bugs me.
・1 min read

If you're working with JSON, say for REST web services, and you don't have the class to unmarshal the response, Visual Studio can automatically generate the class for you:

  1. Open your Visual Studio Project and create a class file. Delete the contents: Class creation
  2. Copy the JSON text string you will need to unmarshal onto the clipboard. Take this example from the JSON Placeholder mock API:
    "userId": 1,
    "id": 1,
    "title": "delectus aut autem",
    "completed": false
Enter fullscreen mode Exit fullscreen mode
  1. Go to Edit > Paste Special > Paste JSON as Classes: Paste Special The result is a class named "Rootobject" that you can use to unmarshal the information on your code.

Original post is here.

Discussion (0)

Forem Open with the Forem app