user2022465
user2022465

Reputation: 13

Json Schema- Parsing error in Json.NET

I am currently facing a problem in parsing my json schema with Json.NET. My schema is composed by an array, whose items can be of two different types, as described in the example below:

"Operations": {
        "type": "array",
        "id": "Operations",
        "required": true,
        "items": {
            "type": [
                {
                    "type": "object",
                    "properties": {
                        "Sale_ID": {
                            "type": "number",
                            "id": "Sale_ID",
                            "required": false
                        },
                  },
                    "additionalProperties": false
                },
                {
                    "type": "object",
                    "properties": {
                        "Purchase_ID": {
                            "type": "number",
                            "id": "Purchase_ID",
                            "required": false
                        },
                  },
                    "additionalProperties": false
                }

This schema was validated in multiple validators, always with success. I'm trying to parse it as a JsonSchema:

JsonSchema js = JsonSchema.Parse(schemaAsString);

However, I get a JsonReaderException:

Exception JSON schema type string token, got StartObject

I'm guessing this happens because my item type is not a string. I would like to know if it is possible to define non-string types in Json.NET, or if this is a known issue/limitation.

Upvotes: 1

Views: 1629

Answers (1)

James Newton-King
James Newton-King

Reputation: 49042

Json.NET does not support complex schemas in the type property.

Update:

Json.NET Schema now has full support for Draft 3 and Draft 4, which includes support for complex schemas in the type property.

Upvotes: 2

Related Questions