(upbeat music)
- [Instructor] So in my stock code I have a lot of errors,
but remember,
I'm going to start from the top and work my way down.
So in the previous video, we already looked at this one,
but let's just do it again.
We've got this error.
It says, "Property keys must be double quoted."
Great, I can do that.
So I'll replace those single quotes with double quotes.
And now that first line is all set.
So I'll look at the second line.
Again, I've got that squiggle and I'll hover over that.
It says, "Value expected."
That's not very helpful.
But if I look at that and think about my rules
and remember that, you know,
this is supposed to be a string
and strings are supposed to be double quoted as well.
And this uses single quotes.
So I'll change those single quotes to double quotes.
And this is an instance where there was an error
and the editor wasn't actually very helpful
in telling us what was wrong.
It just didn't see that as an actual value,
but now we've got that one fixed.
So on the next line,
if I hover over this issue, "Unexpected end of number."
So it's pointing me to the end of the number,
seeing there's something weird.
And if you refer back to the list of rules,
one of the rules is that numbers can't end
with a decimal point.
So I can just take the decimal out here.
Doesn't change the value.
It's still 84 and now that error goes away.
So moving on line five,
we got the error in the value and this says,
"Expected comma."
Now that's not super helpful. So let's think about this.
This is a number and we already corrected an error
with a decimal,
but there's one other rule in JSON about numbers.
And the other rule is that they can't start with a zero,
and this one does.
So I'm going to go ahead and take that zero
off the beginning, called a leading zero in this case.
Again, it doesn't change the value.
It's still a number.
It's still 99.95 and the error goes away.
Then in line six, you may be able to spot this one,
even before I hover over it.
This is one that we saw in earlier videos.
But if I check out, it just says, "Trailing comma."
So right there, the editor is telling me exactly what's up.
It's the last value.
So I can't have a trailing comma on it.
And now that error goes away.
Now I still have one error on the last line.
And again, thinking back to the list of rules,
you may notice right away what's up here,
it's the whole line.
And let's see what the editor has to say, exactly that,
"Comments are not permitted in JSON."
Now I added this here as a reminder
that if you wanted to do the challenge work,
this would be a place to do it.
But first we have to actually take out that comment.
And so here we go.
This is that code,
that JSON content with all of those errors fixed.
Now, if I want to go ahead and do that challenge,
the challenge was to add a key value pair.
That's actually a nested structure.
And so to do that,
first, I have to add a new key.
So I'm going to add a comma after my last existing key.
And then my new key,
I'm going to call that listPriceHistory,
and I'm going to make that value an array in this case.
It doesn't matter what, you can put objects within objects.
You can put arrays within arrays.
Here, I've got an object structure
and I'm going to put a nested array within it.
So square bracket and press Enter.
And then I just want to add a few numerical values
for my listPriceHistory.
And I'm just making these up.
So we'll say,
94.95 and then a comma,
and 85.00 and a comma,
and 124.95.
I'll save that.
And so now I have this array,
the listPriceHistory array, which contains three values.
And that is nested within this overall stock.json structure,
which is an object.