How to use the epJson Schema with C# . Net

asked 2018-04-26 21:12:58 -0500

Tim gravatar image

updated 2018-04-27 07:05:57 -0500

I would like to generate classes from the epJSON schema to use in a C# propgram. I am using NJsonSchema for this and wrote the following code for the conversion:

var schemaTxt = System.IO.File.ReadAllText(path);
var schema =   JsonSchema4.FromJsonAsync(schemaTxt);
var settings = new CSharpGeneratorSettings();
var generator = new CSharpGenerator(schema.Result, settings);
var file = generator.GenerateFile();
System.IO.File.WriteAllText(path + ".cs", file);

This works without errors, however, leads to a list of <string,object> dictionaries that do not carry over the properties from the schema. The structs defined in the "patternProperties" are ignored completely. Is this a non-standard implementation? I am not sure what I am doing wrong and would greatly appreciate a few pointers.

I am pasting a piece of the schema and the corresponding output below.

JSON Schema:

"epJSON_schema_version": "8.9.0", 
"$schema": "", 
"required": [
"properties": {
    "Site:GroundTemperature:Undisturbed:KusudaAchenbach": {
        "name": {
            "is_required": true, 
            "type": "string", 
            "reference": [
        "min_fields": 7.0, 
        "patternProperties": {
            ".*": {
                "required": [
                "properties": {
                    "soil_thermal_conductivity": {
                        "units": "W/m-K", 
                        "minimum": 0.0, 
                        "type": "number", 
                        "exclusiveMinimum": true

                     ... removed several properties for clarity ...

                "type": "object"

C# class output

[Newtonsoft.Json.JsonProperty("Site:GroundTemperature:Undisturbed:KusudaAchenbach", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
        public System.Collections.Generic.Dictionary<string, object> Site_GroundTemperature_Undisturbed_KusudaAchenbach { get; set; } = new System.Collections.Generic.Dictionary<string, object>();
edit retag flag offensive close merge delete