What is a JSON Schema? Intro to JSON
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
đ 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.
đ 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.
đ 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.
đ 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 Schema
đĄPre-validation
đĄData Format
đĄType
đĄProperties
đĄArray
đĄRequired
đĄBoolean
đĄNull
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
what's up guys it's matt collins jones
here also known as
mcj and today we have a video called
what is a json schema in the last video
we covered what is json
we learned that it stands for javascript
object notation
we learned that it is a way to write and
to
notate different pieces of information
that various things can use like
apis and we learned it's a very common
language across
apis and also things like the power
platform which might be why you're
watching this video
so what is a json steamer and why
is this important so json steamer is
the it's like a blueprint for json
so why is this important it's important
because
you can sort of pre-validate the json
that you are receiving
you can say right i want this
payload json i want to get this
information
and when you send it and it's validated
it's the schema
it goes actually this is in the wrong
format
maybe you have a string and it needs to
be a number
maybe it's a number it needs to be a
string maybe it's
blank or null and therefore
something that um the the application at
the other end
won't accept and won't be able to
process
so json schema is a way to pre-validate
that data
to say yes this is the correct format or
this is what you should be sending to us
for our application or our program to be
able to understand it
and then use it so let's take a look at
some examples today
so last time i wrote this bit of json
out
i've changed it slightly because the uh
the friends
anniversary is coming up with a new
episode and i'm very excited about it
but essentially these are the different
types of uh properties inside of our
json
so we have name which is a string
occupation which again is another string
we have age which is a number so we can
see it's kind of different from the
strings with it not being
inside double quotation marks we have is
a dev
false so again we have a boolean true or
false and then we have an array and the
array contains two things so the array
contains
two friends one joey whose occupation is
an actor
and one is chandler whose occupation is
a statistical analysis and data
reconfiguration
um i myself has a gel uh channel bing
job
is what i always explain to people
so this is this is the data that we're
going to send
somewhere so what does a steamer look
like well i've already written that out
for us so let's take a look at the other
tab
so this tab is the exact
is the the schema that'll be used for
the previous screen so it starts off we
have the curly brackets opening at the
top and the bottom
and then it goes on to what's called
types
and properties so the the
type up here is an object so what i'm
saying is
right i'm going to send you a single
piece of information an object of
information
and you're going to deal with it and
that's what the that's what the
information
i we have for the schema is and
therefore that's what this
information is going to be it's going to
be a single object
um the object may contain an array
but it's going to be an object it's
going to be a single piece of
information
properties is here this is just a way to
define that there are things underneath
it
um because we're not setting kind of a
top
level um json sort of like header
or anything like that we're just saying
right okay we need
some way to distinguish right this is
what's going on so we've just called
that properties
and then this opens a bracket here which
as you can see
doesn't close for a little bit so it
closes down here
so we have our our close bracket to
start with where we have the object
and then as soon as we hit that
properties we open it
and it's gonna close down here so that's
to say right
everything contained within this is the
properties or everything
containing this is what we're going to
send you
next we have the name so this is the
name field from the contact here so we
see name and occupation and our first
two
and we know that name is a string we
know occupation is a string
so if we go back to our um steamer we
can see name
open the open the brace here and it says
type
equals or type is string so again this
is going to look a lot like json and
that's because it
is it is a way to know what
sort of json we're getting so again we
have these t-value pairs
but instead of last time where
everything was unique we had like name
and occupation we have name which is the
the key value pair but then it's saying
right okay
that key value pair again denoted by
this
colon here and then open a brace that's
going to have a type and that type is
string
so all this is saying is for the name
the name
type is a string and we're doing the
exact same thing for occupation
and as we know there are commas after
each one again
just denote a new line so we have the
same thing for occupation there
and then we move on to age and age has a
type of integer because that is a number
and again that is taken from the last
screen
and we have is a dev type equals brutal
bullion
so again if i flip back to our example
we can see that all these things
are true so age is a number as we've
said it's not got any
double quotation marks it's just a
number and is a dev
is false so true false beings through
things that are
compatible with json without needing
quotation marks so there we have so
we have our our string we have our
integer
we have our boolean then goes down a bit
further and then we have
the the friends kind of header or the
friends
part of this which is an array and this
array
as we can see opens up here and closes
down here this friends bit will
take everything inside here and this is
saying right okay
this friends bit that key value type is
an array so again it's saying right you
you will you will get an array at some
point in this
um the array will have different objects
or different properties inside of it
but i'm telling you that there's going
to be an array coming and this is the
this is the schema or this is the format
for it
so again items is kind of denoting that
this is going to be
um one of many items um that could be
sent
in an array because we may not know how
big
or how small the array is but we can see
that we've got items
um and that's trying to denote that
level of the array
then here's the type of object so again
we know that
inside of the array we're going to be
sending an object so
inside of the array we're going to be
saying right
this is um an object so this is again
another piece of information
um and it's not and that's what we're
sending
so we're going to send an object and in
this example the object is
joey and uh his his occupation being an
actor
so that's an object just like this whole
json is an object as well so i'm just
really trying to use the terms of like
objects and arrays they're not big and
scary it just means
a thing you know a piece of data a thing
an array is multiple
things so an array can be multiple
objects that we're sending
so again we have uh the properties
opening up that key value pair just to
say
right we don't have like a top level
name for this this is just going to be
everything that's underneath it
and we're going to have name the name is
of type string
and then inside of this properties here
we also have
occupation again of type string so we
kind of see
that it's going to close that bracket
out and say right okay
inside of this object the things that we
are receiving
is a name which is of type string and an
object which is of type string as well
further down we actually have something
that's a little bit optional um
which is funny because it says required
so one of the things that you can
specify in your json
is um for things like arrays what
is required in those arrays and what is
optional
because you may not always get that
information back
in an array um so if it doesn't send
name for instance uh you would not
potentially receive
name so when you're creating an array
you may
not have that name field and therefore
your program may not
create a property or a key value for
name
and a value because it doesn't know it
it's kind of a unique example but what
this allows you to do saying is required
again which is inside of this um this
bracket here and
sorry this items bracket here is saying
right
in my array these are two properties
that are required name and occupation
you can remove this and you can not use
this
as being something that is required so
you can take this out
but what this allows you to do is
specify to the
program that is sending you the json hey
this is required your rain needs to
contain this
so hopefully that makes sense now that's
what you do
for an array but sometimes you may have
objects that will contain a
a value but not contained like a key
would not contain a value
so for instance one of the most common
ones is things like a boolean
so up here in my object i have a boolean
which has a which which is um is a dev
and that's my boolean
so inside my object i know i'm always
going to get these so i don't need to
say that these are required
it's just an array that i'd need to
specify that for
but i'll i may always get is a dev
but i may not get a value with it
now the reason for that is maybe it
doesn't have a value in the source
system
you know there are systems where you
don't put in a yes or no
answer um and therefore it's not
it doesn't have a value so that can
kind of lead to issues with data uh but
when you're sending it something maybe
you need to default those things or
maybe you need to do something else
so in this instance if um someone sent
a json object to me
and is a dev was blank instead of being
a true or false
um because no again is a valid value in
json
it may fall over it may not work
so one of the things you can actually do
is you can actually specify
if um a a key or a value
which would be not so for instance or
could be a different
type so in my type here um what i can do
is i can make this into an array
so put a square bracket here put a
square bracket here
and put that in and then do not like
that
so what that does is that says right is
a dev
can be one of the following types a
boolean
or a null so again i'm creating an array
to say
right there could be multiple values
here this is how you denote this
in a coding language it's an array it's
multiple things it's not a single value
if i was to try and take these scrub
brackets away
it would go um yeah i don't really know
what this is
um we've got a whole unexpected here
because it's just not really figuring it
out
if i have those square brackets straight
brackets in
it will go oh this is an array okay it
can be one of these values
so if someone was to send a json object
with a boolean
out of true or false for is a dev or not
send
that value at all we still have that as
a dev there with just a null value
this json schema would go yep that's
that's fine
that's approved we can let you through
we can
um pro we can use this information that
you've sent and do something with it
so there we have it that is a brief
introduction to
json steamers it's a little bit
complicated that you had around it
especially when you compare
something like this which may now
hopefully
seem really easy to use in terms of
this is what you're used to this is like
a name this is a
value that's all fine when you look at
this
it's a little bit more abstract i would
say but if you break it down into the
simple list components
you will you'll be able to understand
what's going on so here you know
age is an integer is a dev is a boolean
or a null value
that sort of thing plus there are loads
of
json schema creators for you so you can
load in some sample json payloads
like this contact one uh here into
something
and it will pump it out for you into the
steamer
i have a video on that here for using it
in the power platform using empower
automate
and you can check that video out and see
how
um see how these things can be used uh
which is really useful
um but there are other programs
available that will allow you to do that
as well
i will be truthful i did not write this
steamer i
just use power ultimate to generate it
for me uh because life's too short to
write your own streamers
but sometimes you need to and sometimes
you need to edit them like this because
it'll just give you the most
common uh scenario so in this instance
um my is a dev payload was a boolean
so it knew it was a boolean but it
doesn't know it can be not so you may
need to edit it
and that's why this video is really
important to be able to understand
how a streamer is put together to be
able to understand the individual
components of it
then you can edit it you can you can
understand it you know what data you
need to send
and you can edit it if needed as well
i hope you guys enjoyed this video this
is my second video
on my sort of introduction to json so i
hope it was useful
if it was if you could share it with a
friend that would be appreciated
if you could drop a like or make a
comment down below on if this is useful
or what you've maybe used this for
that would be really helpful as well and
i'll see you next time
you
Voir Plus de Vidéos Connexes
Free CCNA | JSON, XML, & YAML | Day 60 | CCNA 200-301 Complete Course
Apache Kafka 101: Schema Registry (2023)
There's Way More to JSON.Stringify Than You Think
4 | PHP Variable and Data Type Tutorial | 2023 | Learn PHP Full Course for Beginners
Data Types Variables And Operators In Python | Python Fundamentals | Great Learning
Azure Service Fabric - Tutorial 17 - Data Packages, Config and Environment Variables
5.0 / 5 (0 votes)