Generate C# classes from JSON Schema

Julien N picture Julien N · Jun 15, 2011 · Viewed 70.1k times · Source

I'm creating a C# WCF Web Service that return a lot of data in a JSON format. The client is an iPad application that is currently being developped by another team, So I'm working on specifications, without example data.
Currently the JSON string is created by the .net framework, my Web Service is returning a C# object containing all the information that are then serialized by the framework using DataContracts.

My problem is that the communication specifications only contain JSON Schema files (based on http://json-schema.org/). In order to facilitate the development I'd like to generate the corresponding classes in C# but as the files contain quite a lot of information and there are a dozen of files, I don't really want to create those classes manually.

So I'm looking for a tool that would allow me either :

  • To generate C# classes from a JSON Schema.
  • To convert a JSON Schema to an XSD file. Then it would be easy to create the classes as there are plenty of tool to generate classes from XSD.

I found a lot of tools to validate a JSON string against a JSON Schema or to generate classes from the JSON string but nothing that seem to help me.
There is JSON.NET but it seems to be a library and not a tool and I didn't found any information about generating classes with it.

So if anyone knows a tools or has an idea on how I could generate those classes (I tried a tool that create the classes in Java but I couldn't make it work).

Answer

SDAL picture SDAL · Apr 20, 2018

Visual Studio 2017 has this feature.

From the menu, choose Edit, Paste Special, Paste JSON As Classes. Paste in the JSON and Visual Studio will create the required classes.

enter image description here