I am working on a remote PC that only has Newtonsoft.Json.dll 12.0.3.23909 and PowerShell 5. I cannot install new software or transfer files as this tool will be used on other PCs and I can't ship other software with mine.
I am trying to validate my json againist a schema. However, regardless of what I do, IsValid is always returning true.
When my schema was draft 6, I used to get this error:
Exception calling "Parse" with "1" argument(s): "Can not convert Array to Boolean."
I changed it to be draft 3. and used "required": true instead of arrays. But now, validation always pass even if I remove a required item.
I wonder what draft can I use with these obsolete methods?
[Newtonsoft.Json.Schema.JsonSchema]::Parse($Schema)
[Newtonsoft.Json.Linq.JObject]::Parse($Json)
[Newtonsoft.Json.Schema.Extensions]::IsValid($json, $schema)
This is my new draft 3 schema. It validates fine online. But in the code, it doesn't catch any errors.
{
"$schema": "http://json-schema.org/draft-03/schema#",
"$ref": "#/definitions/ToShareSchema",
"definitions": {
"ToShareSchema": {
"type": "object",
"additionalProperties": false,
"properties": {
"SC": {
"type": "array",
"items": {
"$ref": "#/definitions/SCI"
},
"minItems": 1,
"required": true
},
"MT": {
"$ref": "#/definitions/MT",
"required": true
}
},
"title": "ToShareSchema"
},
"MT": {
"type": "object",
"required": true,
"additionalProperties": false,
"properties": {
"comps": {
"type": "array",
"items": {
"type": "string"
},
"required": true,
"minItems": 1,
"uniqueItems": true
},
"list": {
"type": "array",
"items": {
"type": "string",
"format": "email"
},
"required": true,
"minItems": 1,
"uniqueItems": true
}
},
"title": "MT"
},
"SCI": {
"type": "object",
"required": true,
"additionalProperties": false,
"properties": {
"SO": {
"type": "string",
"minLength": 1,
"pattern": "^[^\\s]*$"
},
"Bo": {
"type": "array",
"items": {
"type": "string",
"minLength": 1,
"pattern": "^[^\\s]*$",
"enum": ["One", "Two"]
},
"minItems": 1
},
"Me": {
"type": "string",
"minLength": 2,
"required": true
},
"DR": {
"type": "array",
"items": {
"type": "string"
},
"minItems": 1,
"uniqueItems": true,
"required": true
}
},
"oneOf": [
{
"required": ["SO"]
},
{
"required": ["DR"]
}
],
"title": "SCI"
}
}
}