Can you give me an example?

QuestionsQuestions8 SkillsProInsert Data in MongoDBNov, 24 2025
078

Sure! Here's a simple example of using JSON Schema to validate a user profile object:

JSON Schema Example

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "properties": {
    "username": {
      "type": "string",
      "minLength": 3
    },
    "email": {
      "type": "string",
      "format": "email"
    },
    "age": {
      "type": "integer",
      "minimum": 0
    }
  },
  "required": ["username", "email"]
}

Explanation

  • $schema: Specifies the version of JSON Schema being used.
  • type: Indicates that the data should be an object.
  • properties: Defines the expected fields:
    • username: Must be a string with a minimum length of 3 characters.
    • email: Must be a valid email format.
    • age: Must be a non-negative integer.
  • required: Specifies that username and email must be present.

Usage

You can use this schema to validate JSON data representing a user profile. If the data meets the schema's requirements, it is considered valid.

If you have more questions or need further examples, feel free to ask!

0 Comments

no data
Be the first to share your comment!