RicoSuter/NJsonSchema

Extra commas are considered valid

Aperta

#942 aperta il 3 apr 2019

 (2 commenti) (0 reazioni) (0 assegnatari)C# (549 fork)github user discovery
help wantedtype: enhancement

Metriche repository

Star
 (1581 stelle)
Metriche merge PR
 (Merge medio 39g 6h) (1 PR mergiata in 30 g)

Descrizione

I'm using the latest NJsonSchema NuGet package version 9.13.28.

NJsonSchema catches some JSON errors (for example, two commas in a row), but it does not catch the case where there is an extra, trailing comma. For example:

   static void Main()
   {
      var jsonSchemaText =
@"{
  ""$schema"": ""http://json-schema.org/draft-07/schema#"",
  ""type"": ""object"",
  ""title"": ""Test"",
  ""properties"": {
    ""hello"": {
      ""type"": ""string""
    }
  }
}";
      var jsonText =
@"{
  ""hello"": ""world"",
}";
      var schema = JsonSchema4.FromJsonAsync(jsonSchemaText).Result;
      var errors = schema.Validate(jsonText);
   }

Notice the extra comma after "world". NJsonSchema does not report any errors and doesn't throw an exception. https://jsonschemalint.com, for example, correctly reports that the JSON document is invalid. Is there a way to enable a "strict" JSON mode in NJsonSchema? This is important, because having the extra comma in the JSON string will crash the Python parser, for instance.

Guida contributor