Please see:
https://sixgun.wordpress.com/2012/02/09/using-json-net-to-generate-jsonschema[
^].
You should understand that generating metadata from data can be ambiguous; it depends on how representative your data sample is.
[EDIT]
My last paragraph above suggests that this approach may not make a lot of sense; it depends on your goals, which you did not share with us.
I would suggest an alternative approach. You could use JSON only through the
Data Contract:
https://msdn.microsoft.com/en-us/library/ms733127%28v=vs.110%29.aspx[
^],
https://msdn.microsoft.com/en-us/library/system.runtime.serialization.json.datacontractjsonserializer%28v=vs.110%29.aspx[
^].
How is that related to the schema? I'll explain. The serializer referenced about, as well as any other serializer based on data contract and most other serializers, is based on reflection.
When, in your comment, you ask about the "class", it cannot be always the class; generally, this is a set of related types, so their instances form one linked
data graph. The serialization is the tool which gives you the way to persist this graph in a stream and later restore from the stream as it is.
Are you getting the idea?
You need to use reflection on the data classes making a contract, to translate the contract structure into the equivalent JSON schema form. Compared to the fully-fledged serializer, which you already have from .NET FCL, this is a relatively simple task. Why? Because "real" serializer uses
System.Reflection.Emit
to generate a serialization assembly, to reuse serialization code, for performance reasons. Normally, you serialize the schema (metadata) much more rarely than the data, so you call allow yourself to ignore the performance (which also would be good enough; because schema cannot big too big to present a problem, but data can be). Use just
System.Reflection
m without emit and just generate schema JSON string from .NET metadata.
—SA