What is a JSON Schema? Intro to JSON

Matt Collins-Jones
28 May 202115:20

Summary

TLDRIn this educational video, Matt Collins Jones, known as MCJ, explains the concept of JSON Schema, which acts as a blueprint for JSON data. He emphasizes its importance in pre-validating JSON to ensure data integrity and compatibility with applications. Through examples, Matt illustrates how JSON Schema specifies data types and structures, including strings, numbers, booleans, and arrays. He also discusses optional and required properties within arrays and how to handle different data types, such as allowing null values alongside booleans. The video aims to demystify JSON Schema for viewers, providing clarity on its components and practical applications, particularly in APIs and platforms like the Power Platform.

Takeaways

  • πŸ“š JSON stands for JavaScript Object Notation, a common data format used in APIs and platforms like the Power Platform.
  • πŸ›  A JSON Schema acts as a blueprint for JSON, defining the structure and validating the format of JSON data before it's processed.
  • πŸ” Pre-validation using JSON Schema helps to ensure that the JSON data is in the correct format and can be processed by the receiving application.
  • πŸ“ JSON Schema allows you to specify the type of data each key should contain, such as strings, integers, booleans, or arrays.
  • πŸ“‘ The schema uses a structure similar to JSON, with type-value pairs to define the expected data types for each property.
  • πŸ“ˆ The 'type' property in a schema indicates the kind of data expected (e.g., object, array, string, integer, boolean, or null).
  • πŸ”‘ The 'properties' section of a schema outlines the keys and their corresponding data types within a JSON object.
  • πŸ‘₯ The 'items' keyword in a schema is used to define the structure of the elements within an array.
  • πŸ“Œ The 'required' keyword can be used to specify which properties must be included in an array for the data to be valid.
  • πŸ’‘ JSON Schema can also account for optional values or the possibility of null values using type arrays, like ["boolean", "null"].
  • πŸ›‘ Understanding JSON Schema is crucial for developers to correctly interpret and manipulate JSON data, ensuring compatibility and functionality in applications.

Q & A

  • What is JSON used for according to the video?

    -JSON is used for writing and notating different pieces of information that various systems can use, such as APIs and platforms like the Power Platform.

  • What does JSON stand for?

    -JSON stands for JavaScript Object Notation.

  • What is a JSON Schema according to the video?

    -A JSON Schema is like a blueprint for JSON, which is used to pre-validate the JSON data to ensure it is in the correct format before it is processed by an application or program.

  • Why is JSON Schema important?

    -JSON Schema is important because it allows you to pre-validate JSON data, ensuring that the data received is in the correct format and can be processed by the application at the other end.

  • What is an example of a JSON object mentioned in the video?

    -An example of a JSON object mentioned in the video includes properties like 'name', 'occupation', 'age', 'is a dev', and an 'array' containing 'friends' with their respective 'name' and 'occupation'.

  • What does the video suggest for handling JSON data that may not have a value?

    -The video suggests using JSON Schema to specify that certain values can be null, ensuring that the application can still process the data even if some values are missing.

  • What is the purpose of the 'required' keyword in a JSON Schema?

    -The 'required' keyword in a JSON Schema specifies that certain properties must be included in the JSON data for it to be considered valid.

  • How can you specify that a property in a JSON object can be of multiple types?

    -You can specify that a property can be of multiple types by using an array notation in the JSON Schema, listing the possible types.

  • What tool did the video presenter use to generate the JSON Schema example?

    -The video presenter used Power Ultimate to generate the JSON Schema example.

  • What is the significance of the 'type' keyword in a JSON Schema?

    -The 'type' keyword in a JSON Schema is used to define the data type that a property should have, such as 'string', 'integer', 'boolean', or 'null'.

  • Can JSON Schema help in cases where the JSON data structure is complex?

    -Yes, JSON Schema helps in handling complex JSON data structures by providing a clear definition and validation rules for the data, making it easier to understand and process.

Outlines

00:00

πŸ“š Introduction to JSON Schema

Matt Collins Jones, also known as MCJ, introduces the concept of JSON Schema in this video. He builds upon the previous video's content about JSON (JavaScript Object Notation) and explains that JSON Schema acts as a blueprint for JSON data. It allows for pre-validation of JSON data to ensure it is in the correct format before it is processed by applications or programs. MCJ emphasizes the importance of JSON Schema for developers working with APIs and platforms like the Power Platform. He then provides an example of a JSON object containing various data types and proceeds to explain how a corresponding JSON Schema is structured.

05:00

πŸ” Exploring JSON Schema Structure

This paragraph delves deeper into the structure of a JSON Schema. MCJ explains the schema's role in defining the types of data expected in a JSON object, such as strings, integers, booleans, and arrays. He illustrates how each property within the JSON object is represented in the schema with its corresponding data type. The video script includes an example schema that mirrors the JSON object from the previous video, showing how properties like 'name', 'occupation', 'age', 'is a dev', and 'friends' are defined with their respective types. MCJ also discusses the use of 'required' to specify which properties must be included in an array.

10:01

πŸ“ Understanding JSON Schema for Arrays and Optional Properties

MCJ continues the explanation by focusing on arrays within JSON Schema. He clarifies how to define arrays and the objects they contain, using the 'items' keyword to denote the contents of the array. He also touches on the concept of optional properties within arrays, using the 'required' keyword to indicate which properties must be present. The video script provides an example where 'name' and 'occupation' are marked as required within an array of 'friends'. Additionally, MCJ addresses the handling of properties that may not have a value, such as booleans that could be true, false, or null, and how to specify these possibilities within the schema.

15:02

πŸ›  Practical Use of JSON Schema

In the final paragraph, MCJ wraps up the video by highlighting the practical applications of JSON Schema. He mentions the availability of tools that can generate JSON Schema from sample JSON payloads, which can be particularly useful for developers. MCJ also encourages viewers to understand the individual components of a schema so they can edit them as needed. He admits to using a tool called Power Ultimate to generate the schema shown in the video, emphasizing that while it's not always necessary to write schemas from scratch, understanding them is crucial. The video concludes with a call to action for viewers to share the video, like it, or comment if they find the content useful.

Mindmap

Keywords

πŸ’‘JSON

JSON stands for JavaScript Object Notation. It is a lightweight data-interchange format that is easy for humans to read and write and easy for machines to parse and generate. In the video, JSON is the central topic, as it discusses how JSON is used to write and notate different pieces of information for APIs and platforms like the Power Platform.

πŸ’‘JSON Schema

A JSON Schema is like a blueprint for JSON data. It defines the structure and validation rules for a JSON document. The video emphasizes the importance of JSON Schema for pre-validating JSON data to ensure it is in the correct format before it is processed by an application or program.

πŸ’‘Pre-validation

Pre-validation refers to the process of checking data before it is used to ensure it meets certain criteria or standards. In the context of the video, pre-validation is used to verify that the JSON data conforms to the specified schema, which helps prevent errors in data processing.

πŸ’‘Data Format

Data format pertains to the way data is organized, presented, or stored. The video script discusses the importance of data format in JSON, such as strings, numbers, and booleans, and how JSON Schema helps in defining and validating these formats.

πŸ’‘Type

In JSON Schema, 'type' is a keyword used to specify the kind of value an item in a JSON document should be, such as 'string', 'number', 'boolean', or 'object'. The script uses 'type' to illustrate how JSON Schema defines the expected data types for different fields in a JSON document.

πŸ’‘Properties

Properties in JSON refer to the key-value pairs that make up a JSON object. The video script explains how properties are defined within a JSON Schema to outline the structure of the JSON data, including the types of each property.

πŸ’‘Array

An array in JSON is an ordered collection of values. The video script discusses how JSON Schema can define an array with specific types of items it should contain, and how it can specify which items in the array are required.

πŸ’‘Required

The 'required' keyword in JSON Schema is used to indicate that certain properties or items within an array must be present in the JSON data for it to be considered valid. The script gives an example of how 'required' can be used to specify that 'name' and 'occupation' are essential fields in an array of objects.

πŸ’‘Boolean

A boolean in JSON represents true or false values. The video script uses 'is a dev' as an example of a boolean property in a JSON object, and it also explains how JSON Schema can accommodate boolean values or null in certain cases.

πŸ’‘Null

Null in JSON represents the intentional absence of any object value. The script discusses how JSON Schema can be configured to accept null as a valid value for certain properties, which is useful when the source system does not provide a value.

Highlights

Introduction to JSON Schema by Matt Collins Jones, emphasizing its importance as a blueprint for JSON.

Explanation of how JSON Schema allows pre-validation of JSON data to ensure correct format before processing.

Illustration of JSON Schema's role in identifying data format issues such as incorrect string or number types.

Overview of a JSON example with various data types including strings, numbers, booleans, and arrays.

Description of the JSON Schema structure starting with type definitions and moving to properties.

Detailing how the 'type' field in JSON Schema specifies the data type expected for each property.

Use of 'properties' in JSON Schema to define the structure and expected data types within an object.

Explanation of how 'required' in JSON Schema specifies which properties must be included in an array.

Discussion on handling optional properties and the use of 'null' as a potential value in JSON Schema.

Demonstration of how to specify multiple possible types for a value in JSON Schema using arrays.

The practicality of using tools to generate JSON Schema automatically for ease of use.

Matt's admission of using Power Ultimate to generate JSON Schema instead of writing it manually.

Importance of understanding JSON Schema components for editing and customizing to specific needs.

Invitation to watch another video by Matt on using JSON Schema in Power Automate.

Matt's call to action for viewers to share, like, and comment on the video for feedback and engagement.

Transcripts

play00:08

what's up guys it's matt collins jones

play00:10

here also known as

play00:11

mcj and today we have a video called

play00:15

what is a json schema in the last video

play00:18

we covered what is json

play00:20

we learned that it stands for javascript

play00:22

object notation

play00:23

we learned that it is a way to write and

play00:27

to

play00:28

notate different pieces of information

play00:31

that various things can use like

play00:32

apis and we learned it's a very common

play00:35

language across

play00:36

apis and also things like the power

play00:38

platform which might be why you're

play00:40

watching this video

play00:42

so what is a json steamer and why

play00:45

is this important so json steamer is

play00:49

the it's like a blueprint for json

play00:53

so why is this important it's important

play00:56

because

play00:57

you can sort of pre-validate the json

play01:00

that you are receiving

play01:01

you can say right i want this

play01:04

payload json i want to get this

play01:07

information

play01:08

and when you send it and it's validated

play01:11

it's the schema

play01:12

it goes actually this is in the wrong

play01:14

format

play01:15

maybe you have a string and it needs to

play01:18

be a number

play01:18

maybe it's a number it needs to be a

play01:20

string maybe it's

play01:21

blank or null and therefore

play01:25

something that um the the application at

play01:28

the other end

play01:29

won't accept and won't be able to

play01:31

process

play01:32

so json schema is a way to pre-validate

play01:36

that data

play01:37

to say yes this is the correct format or

play01:39

this is what you should be sending to us

play01:41

for our application or our program to be

play01:44

able to understand it

play01:46

and then use it so let's take a look at

play01:49

some examples today

play01:52

so last time i wrote this bit of json

play01:54

out

play01:55

i've changed it slightly because the uh

play01:57

the friends

play01:58

anniversary is coming up with a new

play02:00

episode and i'm very excited about it

play02:02

but essentially these are the different

play02:04

types of uh properties inside of our

play02:06

json

play02:07

so we have name which is a string

play02:09

occupation which again is another string

play02:12

we have age which is a number so we can

play02:14

see it's kind of different from the

play02:15

strings with it not being

play02:17

inside double quotation marks we have is

play02:20

a dev

play02:20

false so again we have a boolean true or

play02:22

false and then we have an array and the

play02:25

array contains two things so the array

play02:27

contains

play02:28

two friends one joey whose occupation is

play02:30

an actor

play02:31

and one is chandler whose occupation is

play02:33

a statistical analysis and data

play02:35

reconfiguration

play02:36

um i myself has a gel uh channel bing

play02:39

job

play02:40

is what i always explain to people

play02:43

so this is this is the data that we're

play02:46

going to send

play02:47

somewhere so what does a steamer look

play02:50

like well i've already written that out

play02:51

for us so let's take a look at the other

play02:52

tab

play02:54

so this tab is the exact

play02:57

is the the schema that'll be used for

play03:00

the previous screen so it starts off we

play03:04

have the curly brackets opening at the

play03:06

top and the bottom

play03:07

and then it goes on to what's called

play03:10

types

play03:10

and properties so the the

play03:13

type up here is an object so what i'm

play03:16

saying is

play03:17

right i'm going to send you a single

play03:20

piece of information an object of

play03:22

information

play03:23

and you're going to deal with it and

play03:24

that's what the that's what the

play03:26

information

play03:27

i we have for the schema is and

play03:29

therefore that's what this

play03:30

information is going to be it's going to

play03:32

be a single object

play03:34

um the object may contain an array

play03:37

but it's going to be an object it's

play03:38

going to be a single piece of

play03:40

information

play03:42

properties is here this is just a way to

play03:46

define that there are things underneath

play03:48

it

play03:48

um because we're not setting kind of a

play03:51

top

play03:51

level um json sort of like header

play03:55

or anything like that we're just saying

play03:57

right okay we need

play03:58

some way to distinguish right this is

play04:00

what's going on so we've just called

play04:01

that properties

play04:03

and then this opens a bracket here which

play04:06

as you can see

play04:07

doesn't close for a little bit so it

play04:09

closes down here

play04:11

so we have our our close bracket to

play04:13

start with where we have the object

play04:15

and then as soon as we hit that

play04:17

properties we open it

play04:19

and it's gonna close down here so that's

play04:21

to say right

play04:22

everything contained within this is the

play04:24

properties or everything

play04:25

containing this is what we're going to

play04:27

send you

play04:29

next we have the name so this is the

play04:31

name field from the contact here so we

play04:34

see name and occupation and our first

play04:35

two

play04:36

and we know that name is a string we

play04:38

know occupation is a string

play04:40

so if we go back to our um steamer we

play04:42

can see name

play04:44

open the open the brace here and it says

play04:46

type

play04:47

equals or type is string so again this

play04:50

is going to look a lot like json and

play04:52

that's because it

play04:52

is it is a way to know what

play04:56

sort of json we're getting so again we

play04:58

have these t-value pairs

play05:00

but instead of last time where

play05:03

everything was unique we had like name

play05:05

and occupation we have name which is the

play05:08

the key value pair but then it's saying

play05:10

right okay

play05:11

that key value pair again denoted by

play05:14

this

play05:14

colon here and then open a brace that's

play05:18

going to have a type and that type is

play05:20

string

play05:20

so all this is saying is for the name

play05:23

the name

play05:24

type is a string and we're doing the

play05:27

exact same thing for occupation

play05:29

and as we know there are commas after

play05:31

each one again

play05:33

just denote a new line so we have the

play05:36

same thing for occupation there

play05:38

and then we move on to age and age has a

play05:41

type of integer because that is a number

play05:44

and again that is taken from the last

play05:46

screen

play05:47

and we have is a dev type equals brutal

play05:50

bullion

play05:50

so again if i flip back to our example

play05:53

we can see that all these things

play05:55

are true so age is a number as we've

play05:58

said it's not got any

play06:00

double quotation marks it's just a

play06:02

number and is a dev

play06:03

is false so true false beings through

play06:06

things that are

play06:07

compatible with json without needing

play06:11

quotation marks so there we have so

play06:15

we have our our string we have our

play06:17

integer

play06:18

we have our boolean then goes down a bit

play06:21

further and then we have

play06:23

the the friends kind of header or the

play06:25

friends

play06:26

part of this which is an array and this

play06:29

array

play06:29

as we can see opens up here and closes

play06:31

down here this friends bit will

play06:34

take everything inside here and this is

play06:36

saying right okay

play06:37

this friends bit that key value type is

play06:40

an array so again it's saying right you

play06:44

you will you will get an array at some

play06:47

point in this

play06:48

um the array will have different objects

play06:51

or different properties inside of it

play06:53

but i'm telling you that there's going

play06:55

to be an array coming and this is the

play06:57

this is the schema or this is the format

play06:59

for it

play07:01

so again items is kind of denoting that

play07:04

this is going to be

play07:05

um one of many items um that could be

play07:08

sent

play07:09

in an array because we may not know how

play07:12

big

play07:12

or how small the array is but we can see

play07:15

that we've got items

play07:17

um and that's trying to denote that

play07:19

level of the array

play07:21

then here's the type of object so again

play07:24

we know that

play07:24

inside of the array we're going to be

play07:26

sending an object so

play07:28

inside of the array we're going to be

play07:30

saying right

play07:31

this is um an object so this is again

play07:34

another piece of information

play07:36

um and it's not and that's what we're

play07:39

sending

play07:40

so we're going to send an object and in

play07:42

this example the object is

play07:44

joey and uh his his occupation being an

play07:47

actor

play07:48

so that's an object just like this whole

play07:51

json is an object as well so i'm just

play07:54

really trying to use the terms of like

play07:56

objects and arrays they're not big and

play07:58

scary it just means

play08:00

a thing you know a piece of data a thing

play08:03

an array is multiple

play08:05

things so an array can be multiple

play08:08

objects that we're sending

play08:11

so again we have uh the properties

play08:13

opening up that key value pair just to

play08:15

say

play08:15

right we don't have like a top level

play08:17

name for this this is just going to be

play08:19

everything that's underneath it

play08:20

and we're going to have name the name is

play08:23

of type string

play08:24

and then inside of this properties here

play08:27

we also have

play08:28

occupation again of type string so we

play08:31

kind of see

play08:32

that it's going to close that bracket

play08:34

out and say right okay

play08:35

inside of this object the things that we

play08:37

are receiving

play08:38

is a name which is of type string and an

play08:41

object which is of type string as well

play08:45

further down we actually have something

play08:46

that's a little bit optional um

play08:49

which is funny because it says required

play08:52

so one of the things that you can

play08:54

specify in your json

play08:56

is um for things like arrays what

play08:59

is required in those arrays and what is

play09:02

optional

play09:03

because you may not always get that

play09:04

information back

play09:06

in an array um so if it doesn't send

play09:10

name for instance uh you would not

play09:12

potentially receive

play09:13

name so when you're creating an array

play09:16

you may

play09:17

not have that name field and therefore

play09:19

your program may not

play09:21

create a property or a key value for

play09:24

name

play09:25

and a value because it doesn't know it

play09:28

it's kind of a unique example but what

play09:30

this allows you to do saying is required

play09:33

again which is inside of this um this

play09:36

bracket here and

play09:37

sorry this items bracket here is saying

play09:40

right

play09:40

in my array these are two properties

play09:44

that are required name and occupation

play09:47

you can remove this and you can not use

play09:49

this

play09:50

as being something that is required so

play09:51

you can take this out

play09:53

but what this allows you to do is

play09:55

specify to the

play09:57

program that is sending you the json hey

play10:00

this is required your rain needs to

play10:02

contain this

play10:04

so hopefully that makes sense now that's

play10:07

what you do

play10:08

for an array but sometimes you may have

play10:11

objects that will contain a

play10:14

a value but not contained like a key

play10:17

would not contain a value

play10:19

so for instance one of the most common

play10:22

ones is things like a boolean

play10:24

so up here in my object i have a boolean

play10:27

which has a which which is um is a dev

play10:31

and that's my boolean

play10:32

so inside my object i know i'm always

play10:34

going to get these so i don't need to

play10:36

say that these are required

play10:37

it's just an array that i'd need to

play10:39

specify that for

play10:40

but i'll i may always get is a dev

play10:44

but i may not get a value with it

play10:47

now the reason for that is maybe it

play10:49

doesn't have a value in the source

play10:50

system

play10:51

you know there are systems where you

play10:53

don't put in a yes or no

play10:55

answer um and therefore it's not

play10:58

it doesn't have a value so that can

play11:01

kind of lead to issues with data uh but

play11:03

when you're sending it something maybe

play11:05

you need to default those things or

play11:07

maybe you need to do something else

play11:08

so in this instance if um someone sent

play11:12

a json object to me

play11:15

and is a dev was blank instead of being

play11:17

a true or false

play11:18

um because no again is a valid value in

play11:21

json

play11:22

it may fall over it may not work

play11:25

so one of the things you can actually do

play11:27

is you can actually specify

play11:29

if um a a key or a value

play11:32

which would be not so for instance or

play11:34

could be a different

play11:35

type so in my type here um what i can do

play11:38

is i can make this into an array

play11:40

so put a square bracket here put a

play11:42

square bracket here

play11:44

and put that in and then do not like

play11:47

that

play11:48

so what that does is that says right is

play11:51

a dev

play11:52

can be one of the following types a

play11:54

boolean

play11:55

or a null so again i'm creating an array

play11:58

to say

play11:58

right there could be multiple values

play12:00

here this is how you denote this

play12:02

in a coding language it's an array it's

play12:05

multiple things it's not a single value

play12:08

if i was to try and take these scrub

play12:10

brackets away

play12:12

it would go um yeah i don't really know

play12:14

what this is

play12:15

um we've got a whole unexpected here

play12:17

because it's just not really figuring it

play12:18

out

play12:19

if i have those square brackets straight

play12:21

brackets in

play12:22

it will go oh this is an array okay it

play12:26

can be one of these values

play12:27

so if someone was to send a json object

play12:29

with a boolean

play12:31

out of true or false for is a dev or not

play12:34

send

play12:34

that value at all we still have that as

play12:36

a dev there with just a null value

play12:39

this json schema would go yep that's

play12:42

that's fine

play12:42

that's approved we can let you through

play12:45

we can

play12:46

um pro we can use this information that

play12:49

you've sent and do something with it

play12:51

so there we have it that is a brief

play12:54

introduction to

play12:55

json steamers it's a little bit

play12:58

complicated that you had around it

play12:59

especially when you compare

play13:01

something like this which may now

play13:03

hopefully

play13:04

seem really easy to use in terms of

play13:08

this is what you're used to this is like

play13:10

a name this is a

play13:11

value that's all fine when you look at

play13:14

this

play13:14

it's a little bit more abstract i would

play13:17

say but if you break it down into the

play13:18

simple list components

play13:20

you will you'll be able to understand

play13:22

what's going on so here you know

play13:23

age is an integer is a dev is a boolean

play13:26

or a null value

play13:28

that sort of thing plus there are loads

play13:31

of

play13:31

json schema creators for you so you can

play13:34

load in some sample json payloads

play13:37

like this contact one uh here into

play13:40

something

play13:40

and it will pump it out for you into the

play13:43

steamer

play13:44

i have a video on that here for using it

play13:47

in the power platform using empower

play13:49

automate

play13:50

and you can check that video out and see

play13:52

how

play13:53

um see how these things can be used uh

play13:55

which is really useful

play13:57

um but there are other programs

play13:59

available that will allow you to do that

play14:01

as well

play14:02

i will be truthful i did not write this

play14:04

steamer i

play14:05

just use power ultimate to generate it

play14:07

for me uh because life's too short to

play14:09

write your own streamers

play14:11

but sometimes you need to and sometimes

play14:12

you need to edit them like this because

play14:14

it'll just give you the most

play14:16

common uh scenario so in this instance

play14:19

um my is a dev payload was a boolean

play14:23

so it knew it was a boolean but it

play14:24

doesn't know it can be not so you may

play14:26

need to edit it

play14:27

and that's why this video is really

play14:29

important to be able to understand

play14:31

how a streamer is put together to be

play14:33

able to understand the individual

play14:34

components of it

play14:36

then you can edit it you can you can

play14:37

understand it you know what data you

play14:39

need to send

play14:40

and you can edit it if needed as well

play14:44

i hope you guys enjoyed this video this

play14:46

is my second video

play14:47

on my sort of introduction to json so i

play14:50

hope it was useful

play14:52

if it was if you could share it with a

play14:54

friend that would be appreciated

play14:56

if you could drop a like or make a

play14:57

comment down below on if this is useful

play15:00

or what you've maybe used this for

play15:01

that would be really helpful as well and

play15:04

i'll see you next time

play15:19

you

Rate This
β˜…
β˜…
β˜…
β˜…
β˜…

5.0 / 5 (0 votes)

Related Tags
JSON SchemaData ValidationAPIsWeb DevelopmentInformation NotationSchema BlueprintJSON StructureData FormatProgramming TutorialTech Education