Skip to content

Commit

Permalink
Add boolean property to employee object schema
Browse files Browse the repository at this point in the history
  • Loading branch information
JeelRajodiya committed May 28, 2024
1 parent a1b5c7d commit 129690b
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 0 deletions.
68 changes: 68 additions & 0 deletions content/01-introduction/03-Boolean/code.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
const code: any = {
type: "object",
properties: {
name: {
type: "string",
},
age: {
type: "number",
},
},
};

const validationSchema = {
type: "object",
properties: {
type: {
type: "string",
const: "object",
},
properties: {
type: "object",
properties: {
name: {
type: "object",
properties: {
type: {
type: "string",
const: "string",
},
},
required: ["type"],
},
age: {
type: "object",
properties: {
type: {
type: "string",
const: "number",
},
},
required: ["type"],
},
isFullTime: {
type: "object",
properties: {
type: {
type: "string",
const: "boolean",
},
},
required: ["type"],
},
},
required: ["name", "age", "isFullTime"],
},
},
required: ["type", "properties"],
};

const solution = structuredClone(code);
solution.properties.isFullTime = {
type: "boolean",
};
module.exports = {
code,
solution,
validationSchema,
};
34 changes: 34 additions & 0 deletions content/01-introduction/03-Boolean/instructions.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
title: "Boolean"
description: "Define a boolean property in a JSON Schema."
keywords: "$schema, type, array, items, string, number"
---

# Boolean

Now we want to define a boolean property for our employee object - `isFullTime`

```json highlightLineStart={4}
{
"name": "John Doe ",
"age": 25,
"isFullTime": true
}
```


## Schema Definition

We just need to define the `isFullTime` property in the schema with the type `boolean`.

```json
{
...
"isFullTime": {
"type": "boolean"
}
}

```
add this definition to the schema which is given to you in the editor

0 comments on commit 129690b

Please sign in to comment.