using System.Collections;
using System.Collections.Generic;
using System.Runtime.Serialization.Formatters;
using System.ComponentModel.DataAnnotations;
using System.Globalization;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Serialization;
using Newtonsoft.Json.Schema;
public static void Test()
foreach (var responseFromServer in GetJson())
Test(responseFromServer);
public static void Test(string responseFromServer)
Console.WriteLine("\nTesting JSON: ");
Console.WriteLine(responseFromServer);
string planElevationListSchema = @"{
'description': 'Plan elevation object array',
'COMMUNITYNUMBER': { 'type': 'string' },
'PLANNUMBER': { 'type': 'string' },
'ELEVATION': { 'type': 'string' }
var schema = JsonSchema.Parse(planElevationListSchema);
var planElevations = JToken.Parse(responseFromServer.ToString());
var isValid = (schema.Type == JsonSchemaType.Array && planElevations.Type != JTokenType.Array
? false : planElevations.IsValid(schema));
Console.WriteLine("isValidRoot = {0}", isValid);
static IEnumerable<string> GetJson()
"{\"COMMUNITYNUMBER\":\"44002050000\",\"PLANNUMBER\":\"1700\",\"ELEVATION\":\"A\"}",
"[{\"COMMUNITYNUMBER\":\"44002050000\",\"PLANNUMBER\":\"1700\",\"ELEVATION\":\"A\"},{\"COMMUNITYNUMBER\":\"44002050000\",\"PLANNUMBER\":\"1700\",\"ELEVATION\":\"B\"},{\"COMMUNITYNUMBER\":\"44002050000\",\"PLANNUMBER\":\"1700\",\"ELEVATION\":\"C\"},{\"COMMUNITYNUMBER\":\"44002050000\",\"PLANNUMBER\":\"1700\",\"ELEVATION\":\"D\"},{\"COMMUNITYNUMBER\":\"44002050000\",\"PLANNUMBER\":\"1800\",\"ELEVATION\":\"A\"},{\"COMMUNITYNUMBER\":\"44002050000\",\"PLANNUMBER\":\"1800\",\"ELEVATION\":\"B\"},{\"COMMUNITYNUMBER\":\"44002050000\",\"PLANNUMBER\":\"1800\",\"ELEVATION\":\"C\"},{\"COMMUNITYNUMBER\":\"44002050000\",\"PLANNUMBER\":\"1800\",\"ELEVATION\":\"D\"},{\"COMMUNITYNUMBER\":\"44002050000\",\"PLANNUMBER\":\"1890\",\"ELEVATION\":\"A\"},{\"COMMUNITYNUMBER\":\"44002050000\",\"PLANNUMBER\":\"1890\",\"ELEVATION\":\"B\"},{\"COMMUNITYNUMBER\":\"44002050000\",\"PLANNUMBER\":\"1890\",\"ELEVATION\":\"C\"},{\"COMMUNITYNUMBER\":\"44002050000\",\"PLANNUMBER\":\"1890\",\"ELEVATION\":\"D\"},{\"COMMUNITYNUMBER\":\"44002050000\",\"PLANNUMBER\":\"2270\",\"ELEVATION\":\"A\"},{\"COMMUNITYNUMBER\":\"44002050000\",\"PLANNUMBER\":\"2270\",\"ELEVATION\":\"B\"},{\"COMMUNITYNUMBER\":\"44002050000\",\"PLANNUMBER\":\"2270\",\"ELEVATION\":\"C\"},{\"COMMUNITYNUMBER\":\"44002050000\",\"PLANNUMBER\":\"2270\",\"ELEVATION\":\"D\"},{\"COMMUNITYNUMBER\":\"44002050000\",\"PLANNUMBER\":\"2440\",\"ELEVATION\":\"A\"},{\"COMMUNITYNUMBER\":\"44002050000\",\"PLANNUMBER\":\"2440\",\"ELEVATION\":\"B\"},{\"COMMUNITYNUMBER\":\"44002050000\",\"PLANNUMBER\":\"2440\",\"ELEVATION\":\"C\"},{\"COMMUNITYNUMBER\":\"44002050000\",\"PLANNUMBER\":\"2440\",\"ELEVATION\":\"D\"}]",
public static void Main()
Console.WriteLine("Environment version: " + Environment.Version);
Console.WriteLine("Json.NET version: " + typeof(JsonSerializer).Assembly.FullName);
Console.WriteLine("Failed with unhandled exception: ");
public class AssertionFailedException : System.Exception
public AssertionFailedException() : base() { }
public AssertionFailedException(string s) : base(s) { }
public static class Assert
public static void IsTrue(bool value)
public static void IsTrue(bool value, string message)
throw new AssertionFailedException(message ?? "failed");