(upbeat music)
- [Instructor] I want to create a schema
for my weather data
and just looking at this data, even without it parsed,
it's got a pretty complicated structure.
So I'd prefer to just use a schema generator.
Now, if you want an extra challenge sitting down,
parsing this data out and then building out level by level,
your own schema is a really great challenge,
but I'm going to walk through just building this out,
using a generator.
So I'm going to start by copying the content
between the quotes,
take that to the clipboard,
and then I'll go over to jsonschema.net
and I'll replace
the existing JSON with my JSON.
And I will go ahead
and make a couple changes to the settings.
So in keyword visibility,
I want to take those examples out just to make the structure
easier to read.
And I want to change that URI to the one that I specified
for this particular schema.
So that's
http://explore california.com/schemas/weather.json.
And then we'll go ahead and save that
and I will go ahead and submit,
and now I have a generated schema on the right.
I'm going to go ahead
and copy that to the clipboard using that button.
And back in my code,
I'm going to go to my schema.js file.
I'll just take those curly braces out
and I'll replace those
with the generated schema... pretty big.
So I'm going to go ahead and save that.
And now I actually want to validate that this generated
schema makes sense
and that it actually works for what I want to do.
So still got that schema on my clipboard.
So over in my validator, which is Ajv,
I'm going to go to the schema variable.
I'm going to select that value and delete it.
And I'm going to paste in my schema,
and then down near the bottom,
I want to take out the value for the second.
Actually, I want to take out the entire second
test function call,
and I want to take out the value
of the first test function calls.
So I have empty parens.
And then, and then back in my files in the data file,
I want to go ahead
and copy everything between the quotes.
And then back in my validator,
I'm going to paste that between the parens
and then scrolling down,
I'm going to click run and see what I get.
And in this case looks like I got an error similar to the
one that I got in the lesson itself.
I have additional items that schema generator threw in there
and that the validator is not feeling good about.
So I'm going to go back to my schema in schema.js,
and I can see I have additional items here on line nine.
I'm going to take that out
and I'm going to do a search
and just make sure,
and I have another instance of additional items
on line 116.
I'm going to take that out as well.
And it looks like there's nothing else
matching addition here.
So there were two instances of that.
I took them both out,
saved my schema,
and now I want to copy just the curly braces
and everything between them.
I'm going to go back to my validator,
scroll up and replace the value of the schema variable.
That's down through line 215.
So I'll delete that.
And then I will paste in what I copied.
So this is my updated schema,
without those two statements that the validator wasn't happy
with before I'll click run again,
can take a second for those old results to clear.
And this time I get valid.
So again, I generated a schema using sample data.
Then I validated that schema
and I chose to accept the recommendations of the validator,
which were different than the recommendations
of the generator.