private void ValidateJsonManatee() { try { txtError.Text = ""; var serializer = new Manatee.Json.Serialization.JsonSerializer(); var json = Manatee.Json.JsonValue.Parse(txtJson.Text); var schemaJson = Manatee.Json.JsonValue.Parse(txtSchema.Text); var schema = new Manatee.Json.Schema.JsonSchema(); schema.FromJson(schemaJson, serializer); var options = new Manatee.Json.Schema.JsonSchemaOptions(); options.OutputFormat = Manatee.Json.Schema.SchemaValidationOutputFormat.Basic; var validationResults = schema.Validate(json, options); if (!validationResults.IsValid) { json = serializer.Serialize(validationResults); txtError.Text = JsonHelper.FormatJson(json.ToString()); } else { txtError.Text = "Valid"; } } catch (Exception ex) { txtError.Text = "Parse error: " + ex.Message; } }
public static void ManateeValidation() { var schemaContent = File.ReadAllText(@"D:\code\test\JsonSchemaTest\JsonSchemaTest\schema.json"); var schemaValue = JsonValue.Parse(schemaContent); var schema = new JsonSchema(); schema.FromJson(schemaValue, new JsonSerializer()); var total = 0; var validCount = 0; using (var rd = new StreamReader(@"D:\code\test\JsonSchemaTest\JsonSchemaTest\oneksrcdata.tsv")) { string line; while ((line = rd.ReadLine()) != null) { var strs = line.Split('\t'); if (strs.Length >= 2) { total++; var json = JsonValue.Parse(strs[1]); var validateResult = schema.Validate(json); if (validateResult.IsValid) { validCount++; } } } } Console.WriteLine("Total: {0}, valid Count: {1}", total, validCount); }
private static void _ManateeDeserializeAndValidate(string dataString, string schemaString) { _manateeWatch.Reset(); _manateeWatch.Start(); var json = JsonValue.Parse(dataString); var schemaJson = JsonValue.Parse(schemaString); var schema = new JsonSchema(); schema.FromJson(schemaJson, _serializer); var result = schema.Validate(json); _manateeWatch.Stop(); }