0

I have a json schema validate function something like following

private void ValidateJsonSchema<T>(string jsonData)
    {
        var schema = JsonSchema.FromType<T>();
        var errors = schema.Validate(jsonData);
    }

the param jsonData is the content of the response, but there is sometimes it will be an array like following

[
    {
        "id": "123",
        "title": "abc"
    },
    {
        "id": "456",
        "title": "def"
    }
]

so how can I handle this?

Shabari nath k
  • 920
  • 1
  • 10
  • 23
cz.g
  • 1
  • 1

1 Answers1

0

I tried following code and it works:

        var schema = JsonSchema.FromType(type);
        var jtoken = JToken.Parse(jsonData);
        if (jtoken.Type == JTokenType.Array)
            schema.Type = JsonObjectType.Array;
        var errors = schema.Validate(jtoken);
cz.g
  • 1
  • 1