0

Basically I want to extract JsonSchema from Json string at runtime(Can't use Tools), found no library to do this. Other way is to first Convert JSON to Class(Found one Open Source Code) then create JsonSchema using JSON.NET as below.

var generator = new JSchemaGenerator();
JSchema schema = generator.Generate(typeof(Rootobject));

But Rootobject class is not known at compile time, so I'm getting compile time error. Is there any other way to do this? Please help

  • did you try using dynamic object , reference :http://stackoverflow.com/questions/3142495/deserialize-json-into-c-sharp-dynamic-object PS: if i misunderstood your question please correct me – Vikas Mar 23 '16 at 06:40

1 Answers1

0

The best way I can think of is to use your code to generate a class's source code, compile that using the CodeDOM, load the generated assembly and generate the Schema for that object then.

Information on using the CodeDOM to build an Assembly at runtime can be found on MSDN here: Generating and Compiling Source Code from a CodeDOM graph (it's the second headline you'd be interested in).

Information on how to load the Assembly can be found on MSDN here: How to: Load Assemblies into an Application Domain

Hope that helps in solving your problem.

Oliver Ulm
  • 531
  • 3
  • 8