Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generate C# classes from JSON Schema [closed]

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).

like image 539
Julien N Avatar asked Jun 15 '11 13:06

Julien N


People also ask

What is C Code generation?

Code generation from the Wolfram Language involves converting programs written in the Wolfram Language into other languages and then supporting them so that they can be executed. The Wolfram System compiler provides a system for code generation into the C language.

Can you write C in MATLAB?

In MATLAB®, you can extend your C and C++ code with a MEX function and call it like any MATLAB built-in function. That means you can use existing C and C++ code without rewriting your algorithms in MATLAB. MEX functions enable C and C++ code to create and modify MATLAB arrays in the MATLAB workspace.

Can Simulink generate C Code?

Simulink® Coder™ generates standalone C and C++ code from Simulink models for deployment in a wide variety of applications.


1 Answers

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

like image 195
SDAL Avatar answered Sep 23 '22 13:09

SDAL