0

Im trying to use json schema, here with a simple example. Im using the site: http://www.jsonschemavalidator.net/

Schema:

{ 
      'Foods':
      { 
        'type': 'array', 
        'items':
        {
          'GoodFoods': { 'type':'string' },
          'NastyFoods': { 'type':'string' },
          'BlendFoods': { 'type': 'string' }
        },      
        'required': ['BlendFoods'],
      }
}

Input JSON:

{
  "Foods": 
  [
      {
        "GoodFoods": "Pasta",
        "NastyFoods": true,

      }
  ]
}

The idea here is that it should complain that "BlendFoods" property is missing and that the NastyFoods is a boolean not a string. But instead it says "No errors found. JSON Validates against the schema". That is not what I want.

I tried so much with this but cant figure out what Im doing wrong in the schema, any ideas?

Best regards Rob

2 Answers 2

5

The corrected schema:

{
  "type": "object",
  "properties": {
    "Foods": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "GoodFoods": {
            "type": "string"
          },
          "NastyFoods": {
            "type": "string"
          },
          "BlendFoods": {
            "type": "string"
          }
        },
        "required": [
          "BlendFoods"
        ]
      }
    }
  }
}

Please see this site for reference and help.

0

There's an extra comma after true.

try this:

  {
      "Foods": 
      [
          {
            "GoodFoods": "Pasta",
            "NastyFoods": true

          }
      ]
    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.