[Script Info] Title: [Events] Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text Dialogue: 0,0:00:00.04,0:00:04.01,Default,,0000,0000,0000,,In this video, we'll see a demonstration of JSON data. Dialogue: 0,0:00:04.01,0:00:05.08,Default,,0000,0000,0000,,As a reminder, JSON stands for Dialogue: 0,0:00:05.08,0:00:08.00,Default,,0000,0000,0000,,Java Script Object Notation, and Dialogue: 0,0:00:08.00,0:00:09.08,Default,,0000,0000,0000,,it's a standard for writing Dialogue: 0,0:00:09.08,0:00:13.08,Default,,0000,0000,0000,,data objects into human readable format, typically in a file. Dialogue: 0,0:00:13.08,0:00:16.01,Default,,0000,0000,0000,,It's useful for exchanging data Dialogue: 0,0:00:16.01,0:00:18.01,Default,,0000,0000,0000,,between programs, and generally Dialogue: 0,0:00:18.01,0:00:20.01,Default,,0000,0000,0000,,because it's quite flexible, it's useful Dialogue: 0,0:00:20.01,0:00:23.01,Default,,0000,0000,0000,,for representing and for storing data that's semi-structured. Dialogue: 0,0:00:23.01,0:00:24.08,Default,,0000,0000,0000,,A reminder of the Dialogue: 0,0:00:24.08,0:00:26.09,Default,,0000,0000,0000,,basic constructs in JSON, we Dialogue: 0,0:00:26.09,0:00:28.00,Default,,0000,0000,0000,,have the atomic value, such Dialogue: 0,0:00:28.00,0:00:30.03,Default,,0000,0000,0000,,as integers and strings and so on. Dialogue: 0,0:00:30.03,0:00:31.07,Default,,0000,0000,0000,,And then we have two types of Dialogue: 0,0:00:31.07,0:00:33.02,Default,,0000,0000,0000,,composite things; we have Dialogue: 0,0:00:33.02,0:00:34.00,Default,,0000,0000,0000,,objects that are sets of Dialogue: 0,0:00:34.00,0:00:38.05,Default,,0000,0000,0000,,label-value pairs and then we have arrays that are lists of values. Dialogue: 0,0:00:38.05,0:00:40.03,Default,,0000,0000,0000,,In the demonstration, we'll go through Dialogue: 0,0:00:40.03,0:00:41.09,Default,,0000,0000,0000,,in more detail the basic constructs Dialogue: 0,0:00:41.09,0:00:44.00,Default,,0000,0000,0000,,of JSON and we'll look at Dialogue: 0,0:00:44.00,0:00:46.03,Default,,0000,0000,0000,,some tactic correctness, we'll demonstrate Dialogue: 0,0:00:46.03,0:00:47.01,Default,,0000,0000,0000,,the flexibility of the data Dialogue: 0,0:00:47.01,0:00:49.02,Default,,0000,0000,0000,,model and then we'll Dialogue: 0,0:00:49.02,0:00:50.09,Default,,0000,0000,0000,,look briefly at JSON's schema, Dialogue: 0,0:00:50.09,0:00:52.08,Default,,0000,0000,0000,,not widely used yet but Dialogue: 0,0:00:52.08,0:00:54.03,Default,,0000,0000,0000,,still fairly interesting to look at Dialogue: 0,0:00:54.03,0:00:55.09,Default,,0000,0000,0000,,and we'll look at some validation Dialogue: 0,0:00:55.09,0:00:59.04,Default,,0000,0000,0000,,of JSON data against a particular schema. Dialogue: 0,0:00:59.04,0:01:00.06,Default,,0000,0000,0000,,So, here's the JSON Dialogue: 0,0:01:00.06,0:01:03.00,Default,,0000,0000,0000,,data that we're gonna be working with during this demo. Dialogue: 0,0:01:03.00,0:01:04.07,Default,,0000,0000,0000,,It's the same data that appeared Dialogue: 0,0:01:04.07,0:01:07.00,Default,,0000,0000,0000,,in the slides, in the introduction Dialogue: 0,0:01:07.00,0:01:08.04,Default,,0000,0000,0000,,to JSON, but now we're going Dialogue: 0,0:01:08.04,0:01:11.01,Default,,0000,0000,0000,,to look into the components of the data. Dialogue: 0,0:01:11.01,0:01:13.02,Default,,0000,0000,0000,,It's also by the way, the Dialogue: 0,0:01:13.02,0:01:14.01,Default,,0000,0000,0000,,same example pretty much that we Dialogue: 0,0:01:14.01,0:01:17.01,Default,,0000,0000,0000,,used for XML, it's reformatted Dialogue: 0,0:01:17.01,0:01:18.06,Default,,0000,0000,0000,,of course to meet the JSON Dialogue: 0,0:01:18.06,0:01:22.01,Default,,0000,0000,0000,,data model, but you can compare the two directly. Dialogue: 0,0:01:22.01,0:01:23.06,Default,,0000,0000,0000,,Lastly, we do have Dialogue: 0,0:01:23.06,0:01:25.06,Default,,0000,0000,0000,,the file for the data on Dialogue: 0,0:01:25.06,0:01:26.07,Default,,0000,0000,0000,,the website, and I do Dialogue: 0,0:01:26.07,0:01:28.00,Default,,0000,0000,0000,,suggest that you download the Dialogue: 0,0:01:28.00,0:01:29.01,Default,,0000,0000,0000,,file so that you can Dialogue: 0,0:01:29.01,0:01:31.05,Default,,0000,0000,0000,,take a look at it closely on your own computer. Dialogue: 0,0:01:31.05,0:01:32.03,Default,,0000,0000,0000,,All right. Dialogue: 0,0:01:32.03,0:01:33.05,Default,,0000,0000,0000,,So, let's see what we have, Dialogue: 0,0:01:33.05,0:01:34.08,Default,,0000,0000,0000,,right now we're in Dialogue: 0,0:01:34.08,0:01:36.07,Default,,0000,0000,0000,,an editor for JSON data. Dialogue: 0,0:01:36.07,0:01:38.01,Default,,0000,0000,0000,,It happens to be the Eclipse Dialogue: 0,0:01:38.01,0:01:38.09,Default,,0000,0000,0000,,editor and we're going to Dialogue: 0,0:01:38.09,0:01:39.09,Default,,0000,0000,0000,,make make some edits to the Dialogue: 0,0:01:39.09,0:01:41.09,Default,,0000,0000,0000,,file after we look through Dialogue: 0,0:01:41.09,0:01:43.07,Default,,0000,0000,0000,,the constructs of the file. Dialogue: 0,0:01:43.07,0:01:45.07,Default,,0000,0000,0000,,So, this is JSON Dialogue: 0,0:01:45.07,0:01:48.01,Default,,0000,0000,0000,,data representing books and Dialogue: 0,0:01:48.01,0:01:49.06,Default,,0000,0000,0000,,magazines, and we have Dialogue: 0,0:01:49.06,0:01:52.04,Default,,0000,0000,0000,,a little more information about our books and our magazines. Dialogue: 0,0:01:52.04,0:01:53.09,Default,,0000,0000,0000,,So, at the outermost, the Dialogue: 0,0:01:53.09,0:01:57.04,Default,,0000,0000,0000,,curly brace indicates that this is a JSON object. Dialogue: 0,0:01:57.04,0:01:59.01,Default,,0000,0000,0000,,And as a reminder, an object Dialogue: 0,0:01:59.01,0:02:01.04,Default,,0000,0000,0000,,is a set of label-value Dialogue: 0,0:02:01.04,0:02:03.06,Default,,0000,0000,0000,,pairs, separated by commas. Dialogue: 0,0:02:03.06,0:02:07.01,Default,,0000,0000,0000,,So, our first value is the label "books". And Dialogue: 0,0:02:07.01,0:02:09.07,Default,,0000,0000,0000,,then our first element in Dialogue: 0,0:02:09.07,0:02:11.06,Default,,0000,0000,0000,,the object is the label books Dialogue: 0,0:02:11.06,0:02:14.05,Default,,0000,0000,0000,,and this big value and the Dialogue: 0,0:02:14.05,0:02:16.00,Default,,0000,0000,0000,,second, so there's only two label-value Dialogue: 0,0:02:16.00,0:02:17.08,Default,,0000,0000,0000,,pairs here, is the Dialogue: 0,0:02:17.08,0:02:21.02,Default,,0000,0000,0000,,label magazines and this big value here. Dialogue: 0,0:02:21.02,0:02:23.09,Default,,0000,0000,0000,,And let's take a look first at magazines. Dialogue: 0,0:02:23.09,0:02:25.02,Default,,0000,0000,0000,,So magazines, again, is the Dialogue: 0,0:02:25.02,0:02:26.04,Default,,0000,0000,0000,,label and the value we Dialogue: 0,0:02:26.04,0:02:27.08,Default,,0000,0000,0000,,can see with the square Dialogue: 0,0:02:27.08,0:02:30.02,Default,,0000,0000,0000,,brackets here is an array. Dialogue: 0,0:02:30.02,0:02:31.06,Default,,0000,0000,0000,,An array is a list of Dialogue: 0,0:02:31.06,0:02:33.03,Default,,0000,0000,0000,,values and here we Dialogue: 0,0:02:33.03,0:02:35.01,Default,,0000,0000,0000,,have two values in our array. Dialogue: 0,0:02:35.01,0:02:37.00,Default,,0000,0000,0000,,They're still composite values. Dialogue: 0,0:02:37.00,0:02:38.06,Default,,0000,0000,0000,,So, we have two values, each Dialogue: 0,0:02:38.06,0:02:40.03,Default,,0000,0000,0000,,of which is an object, Dialogue: 0,0:02:40.03,0:02:42.01,Default,,0000,0000,0000,,a set of label-value pairs. Dialogue: 0,0:02:42.01,0:02:46.07,Default,,0000,0000,0000,,Let me mention, sometimes people call these labels 'properties', by the way. Dialogue: 0,0:02:46.07,0:02:48.03,Default,,0000,0000,0000,,Okay. So, now we are inside Dialogue: 0,0:02:48.03,0:02:49.01,Default,,0000,0000,0000,,our 2 objects that are Dialogue: 0,0:02:49.01,0:02:53.01,Default,,0000,0000,0000,,the 2 elements in the array that's the value of magazines. Dialogue: 0,0:02:53.01,0:02:54.01,Default,,0000,0000,0000,,And each one of those has Dialogue: 0,0:02:54.01,0:02:56.09,Default,,0000,0000,0000,,3 labels and 3 values. Dialogue: 0,0:02:56.09,0:02:58.09,Default,,0000,0000,0000,,And now we're finally down to the base values. Dialogue: 0,0:02:58.09,0:03:00.00,Default,,0000,0000,0000,,So, we have the title being "National Dialogue: 0,0:03:00.00,0:03:02.03,Default,,0000,0000,0000,,Geographic", a string, the Dialogue: 0,0:03:02.03,0:03:04.00,Default,,0000,0000,0000,,month being January, a string Dialogue: 0,0:03:04.00,0:03:06.03,Default,,0000,0000,0000,,and the year 2009, where 2009 is an integer. Dialogue: 0,0:03:06.03,0:03:08.06,Default,,0000,0000,0000,,And again, we have Dialogue: 0,0:03:08.06,0:03:12.01,Default,,0000,0000,0000,,another object here that's a different magazine Dialogue: 0,0:03:12.01,0:03:15.03,Default,,0000,0000,0000,,with a different name, month and happens to be the same year. Dialogue: 0,0:03:15.03,0:03:16.07,Default,,0000,0000,0000,,Now, these two have exactly the Dialogue: 0,0:03:16.07,0:03:18.01,Default,,0000,0000,0000,,same structure but they don't Dialogue: 0,0:03:18.01,0:03:19.04,Default,,0000,0000,0000,,have to and we will Dialogue: 0,0:03:19.04,0:03:21.10,Default,,0000,0000,0000,,see that as we start editing the file. Dialogue: 0,0:03:21.10,0:03:23.02,Default,,0000,0000,0000,,But before we edit the file, Dialogue: 0,0:03:23.02,0:03:24.06,Default,,0000,0000,0000,,let's go and look at Dialogue: 0,0:03:24.06,0:03:26.01,Default,,0000,0000,0000,,our books here. Dialogue: 0,0:03:26.01,0:03:28.06,Default,,0000,0000,0000,,The value of our other Dialogue: 0,0:03:28.06,0:03:30.01,Default,,0000,0000,0000,,label-value pair inside the Dialogue: 0,0:03:30.01,0:03:32.00,Default,,0000,0000,0000,,outermost object, "books" is Dialogue: 0,0:03:32.00,0:03:34.03,Default,,0000,0000,0000,,also an array, and Dialogue: 0,0:03:34.03,0:03:35.09,Default,,0000,0000,0000,,the array in this case also Dialogue: 0,0:03:35.09,0:03:38.10,Default,,0000,0000,0000,,has just two elements, so we've represented two books here. Dialogue: 0,0:03:38.10,0:03:40.04,Default,,0000,0000,0000,,It's a little more complicated than the Dialogue: 0,0:03:40.04,0:03:42.06,Default,,0000,0000,0000,,magazines, but those elements Dialogue: 0,0:03:42.06,0:03:45.07,Default,,0000,0000,0000,,are still objects that are label-value pairs. Dialogue: 0,0:03:45.07,0:03:47.04,Default,,0000,0000,0000,,So, we have now the ISBN, Dialogue: 0,0:03:47.04,0:03:49.01,Default,,0000,0000,0000,,the price, the addition, the title, Dialogue: 0,0:03:49.01,0:03:51.10,Default,,0000,0000,0000,,all either integers or strings, Dialogue: 0,0:03:51.10,0:03:54.08,Default,,0000,0000,0000,,and then we have one nested composite Dialogue: 0,0:03:54.08,0:03:56.02,Default,,0000,0000,0000,,object which is the authors Dialogue: 0,0:03:56.02,0:03:57.08,Default,,0000,0000,0000,,and that's an array again. Dialogue: 0,0:03:57.08,0:04:02.03,Default,,0000,0000,0000,,So, the array again, is indicated by the square brackets. Dialogue: 0,0:04:02.03,0:04:04.00,Default,,0000,0000,0000,,And inside this array, we Dialogue: 0,0:04:04.00,0:04:06.01,Default,,0000,0000,0000,,have two authors and each Dialogue: 0,0:04:06.01,0:04:07.04,Default,,0000,0000,0000,,of the authors has a first Dialogue: 0,0:04:07.04,0:04:08.08,Default,,0000,0000,0000,,name and a last name, Dialogue: 0,0:04:08.08,0:04:10.04,Default,,0000,0000,0000,,but again, that uniformity is Dialogue: 0,0:04:10.04,0:04:13.03,Default,,0000,0000,0000,,not required by the model itself, as we'll see. Dialogue: 0,0:04:13.03,0:04:15.04,Default,,0000,0000,0000,,So, as I mentioned, Dialogue: 0,0:04:15.04,0:04:16.07,Default,,0000,0000,0000,,this is actually an editor for Dialogue: 0,0:04:16.07,0:04:19.03,Default,,0000,0000,0000,,JSON data and we're going to come back to this editor in a moment. Dialogue: 0,0:04:19.03,0:04:20.00,Default,,0000,0000,0000,,But what I wanted to do is Dialogue: 0,0:04:20.00,0:04:22.01,Default,,0000,0000,0000,,show the same data Dialogue: 0,0:04:22.01,0:04:23.07,Default,,0000,0000,0000,,in a browser because browsers Dialogue: 0,0:04:23.07,0:04:25.04,Default,,0000,0000,0000,,actually offer some nice features Dialogue: 0,0:04:25.04,0:04:27.09,Default,,0000,0000,0000,,for navigating in JSON. Dialogue: 0,0:04:27.09,0:04:28.07,Default,,0000,0000,0000,,So here we are in the Dialogue: 0,0:04:28.07,0:04:30.03,Default,,0000,0000,0000,,Chrome browser, which has nice Dialogue: 0,0:04:30.03,0:04:32.07,Default,,0000,0000,0000,,features for navigating JSON, Dialogue: 0,0:04:32.07,0:04:34.06,Default,,0000,0000,0000,,and other browsers do as well. Dialogue: 0,0:04:34.06,0:04:35.10,Default,,0000,0000,0000,,We can see here again that we Dialogue: 0,0:04:35.10,0:04:37.05,Default,,0000,0000,0000,,have an object in Dialogue: 0,0:04:37.05,0:04:39.00,Default,,0000,0000,0000,,our JSON data, that consists Dialogue: 0,0:04:39.00,0:04:40.08,Default,,0000,0000,0000,,of two label-value pairs; Dialogue: 0,0:04:40.08,0:04:42.07,Default,,0000,0000,0000,,books and magazines, which are Dialogue: 0,0:04:42.07,0:04:43.06,Default,,0000,0000,0000,,currently closed and and then Dialogue: 0,0:04:43.06,0:04:47.02,Default,,0000,0000,0000,,this plus allows us to open them up, and see the structure. Dialogue: 0,0:04:47.02,0:04:48.08,Default,,0000,0000,0000,,For example, we open magazines Dialogue: 0,0:04:48.08,0:04:52.02,Default,,0000,0000,0000,,and we see that magazines is an array containing two objects. Dialogue: 0,0:04:52.02,0:04:53.00,Default,,0000,0000,0000,,We can open one of those Dialogue: 0,0:04:53.00,0:04:55.09,Default,,0000,0000,0000,,objects, and see that the three label-value pairs. Dialogue: 0,0:04:55.09,0:04:59.06,Default,,0000,0000,0000,,Now we're at the lowest levels and similarly for the other object. Dialogue: 0,0:04:59.06,0:05:00.07,Default,,0000,0000,0000,,We can see here that Books Dialogue: 0,0:05:00.07,0:05:03.01,Default,,0000,0000,0000,,is also an array, and we go ahead and open it up. Dialogue: 0,0:05:03.01,0:05:05.01,Default,,0000,0000,0000,,It's an array of two objects. Dialogue: 0,0:05:05.01,0:05:06.00,Default,,0000,0000,0000,,We open one of those Dialogue: 0,0:05:06.00,0:05:07.09,Default,,0000,0000,0000,,objects and we see again Dialogue: 0,0:05:07.09,0:05:09.06,Default,,0000,0000,0000,,the set of label-value pairs, Dialogue: 0,0:05:09.06,0:05:10.01,Default,,0000,0000,0000,,where one of the values Dialogue: 0,0:05:10.01,0:05:12.06,Default,,0000,0000,0000,,is a further nesting. Dialogue: 0,0:05:12.06,0:05:14.04,Default,,0000,0000,0000,,It's an array and we open Dialogue: 0,0:05:14.04,0:05:15.04,Default,,0000,0000,0000,,that array, and we see Dialogue: 0,0:05:15.04,0:05:16.07,Default,,0000,0000,0000,,two objects, and we open Dialogue: 0,0:05:16.07,0:05:19.04,Default,,0000,0000,0000,,them and finally see the data at the lowest levels. Dialogue: 0,0:05:19.04,0:05:21.05,Default,,0000,0000,0000,,So again, the browser Dialogue: 0,0:05:21.05,0:05:22.06,Default,,0000,0000,0000,,here gives us a nice way Dialogue: 0,0:05:22.06,0:05:26.09,Default,,0000,0000,0000,,to navigate the JSON data and see its structure. Dialogue: 0,0:05:26.09,0:05:28.10,Default,,0000,0000,0000,,So now we're back to our JSON editor. Dialogue: 0,0:05:28.10,0:05:30.08,Default,,0000,0000,0000,,By the way, this editor, Eclipse, does Dialogue: 0,0:05:30.08,0:05:32.06,Default,,0000,0000,0000,,also have some features for Dialogue: 0,0:05:32.06,0:05:34.02,Default,,0000,0000,0000,,opening and closing the structure Dialogue: 0,0:05:34.02,0:05:35.10,Default,,0000,0000,0000,,of the data, but it's Dialogue: 0,0:05:35.10,0:05:38.01,Default,,0000,0000,0000,,not quite as nice as the browser that we use. Dialogue: 0,0:05:38.01,0:05:39.08,Default,,0000,0000,0000,,So we decided to use the browser instead. Dialogue: 0,0:05:39.08,0:05:40.01,Default,,0000,0000,0000,,What we are going to Dialogue: 0,0:05:40.01,0:05:42.03,Default,,0000,0000,0000,,use the editor for is to Dialogue: 0,0:05:42.03,0:05:43.05,Default,,0000,0000,0000,,make some changes to the Dialogue: 0,0:05:43.05,0:05:44.08,Default,,0000,0000,0000,,JSON data and see which Dialogue: 0,0:05:44.08,0:05:47.06,Default,,0000,0000,0000,,changes are legal and which aren't. Dialogue: 0,0:05:47.06,0:05:50.04,Default,,0000,0000,0000,,So, let's take a look at the first change, a very simple one. Dialogue: 0,0:05:50.04,0:05:52.00,Default,,0000,0000,0000,,What if we forgot a comma. Dialogue: 0,0:05:52.00,0:05:53.03,Default,,0000,0000,0000,,Well, when we try to Dialogue: 0,0:05:53.03,0:05:54.04,Default,,0000,0000,0000,,save that file, we get a Dialogue: 0,0:05:54.04,0:05:55.05,Default,,0000,0000,0000,,little notice that we have an Dialogue: 0,0:05:55.05,0:05:56.09,Default,,0000,0000,0000,,error, we expected an Dialogue: 0,0:05:56.09,0:05:58.08,Default,,0000,0000,0000,,N value, so that's a Dialogue: 0,0:05:58.08,0:06:02.07,Default,,0000,0000,0000,,pretty straightforward mistake, let's put that comma back. Dialogue: 0,0:06:02.07,0:06:04.07,Default,,0000,0000,0000,,Let's say insert an Dialogue: 0,0:06:04.07,0:06:07.06,Default,,0000,0000,0000,,extra brace somewhere here, for whatever reason. Dialogue: 0,0:06:07.06,0:06:09.08,Default,,0000,0000,0000,,We accidentally put in an extra brace. Dialogue: 0,0:06:09.08,0:06:13.02,Default,,0000,0000,0000,,Again we see that that's marked as an error. Dialogue: 0,0:06:13.02,0:06:13.10,Default,,0000,0000,0000,,So an error that can Dialogue: 0,0:06:13.10,0:06:15.03,Default,,0000,0000,0000,,be fairly common to make is Dialogue: 0,0:06:15.03,0:06:18.01,Default,,0000,0000,0000,,to forget to put quotes around strings. Dialogue: 0,0:06:18.01,0:06:20.02,Default,,0000,0000,0000,,So, for example, this ISBN Dialogue: 0,0:06:20.02,0:06:23.06,Default,,0000,0000,0000,,number here, if we don't quote it, we're gonna get an error. Dialogue: 0,0:06:23.06,0:06:24.08,Default,,0000,0000,0000,,As we'll see the only things that can Dialogue: 0,0:06:24.08,0:06:27.00,Default,,0000,0000,0000,,be unquoted are numbers and Dialogue: 0,0:06:27.00,0:06:29.01,Default,,0000,0000,0000,,the values null, true and false. Dialogue: 0,0:06:29.01,0:06:31.07,Default,,0000,0000,0000,,So, let's put our quotes back there. Dialogue: 0,0:06:31.07,0:06:33.02,Default,,0000,0000,0000,,Now, actually, even more Dialogue: 0,0:06:33.02,0:06:34.04,Default,,0000,0000,0000,,common is to forget to Dialogue: 0,0:06:34.04,0:06:37.07,Default,,0000,0000,0000,,put quotes around the labels in label-value pairs. Dialogue: 0,0:06:37.07,0:06:40.08,Default,,0000,0000,0000,,But if we forget to quote that, that's going to be an error as well. Dialogue: 0,0:06:40.08,0:06:41.08,Default,,0000,0000,0000,,You might have noticed, by the Dialogue: 0,0:06:41.08,0:06:43.05,Default,,0000,0000,0000,,way, when we use the browser Dialogue: 0,0:06:43.05,0:06:44.09,Default,,0000,0000,0000,,that the browser didn't even show Dialogue: 0,0:06:44.09,0:06:46.01,Default,,0000,0000,0000,,us the quotes in the labels. Dialogue: 0,0:06:46.01,0:06:47.10,Default,,0000,0000,0000,,But you do when you make Dialogue: 0,0:06:47.10,0:06:51.07,Default,,0000,0000,0000,,the raw JSON data, you do need to include those quotes. Dialogue: 0,0:06:51.07,0:06:56.02,Default,,0000,0000,0000,,Speaking of quotes, what if we quoted our price here. Dialogue: 0,0:06:56.02,0:06:57.02,Default,,0000,0000,0000,,Well that's actually not an Dialogue: 0,0:06:57.02,0:06:58.07,Default,,0000,0000,0000,,error, because now we've simply turned Dialogue: 0,0:06:58.07,0:07:00.06,Default,,0000,0000,0000,,price into a string, and Dialogue: 0,0:07:00.06,0:07:03.03,Default,,0000,0000,0000,,string values are perfectly well allowed anywhere. Dialogue: 0,0:07:03.03,0:07:04.05,Default,,0000,0000,0000,,Now we'll see when we use Dialogue: 0,0:07:04.05,0:07:05.06,Default,,0000,0000,0000,,JSON's schema that we Dialogue: 0,0:07:05.06,0:07:07.02,Default,,0000,0000,0000,,can make restrictions that don't allow Dialogue: 0,0:07:07.02,0:07:08.09,Default,,0000,0000,0000,,strings in certain places, but Dialogue: 0,0:07:08.09,0:07:10.01,Default,,0000,0000,0000,,just for syntactic correctness of Dialogue: 0,0:07:10.01,0:07:15.04,Default,,0000,0000,0000,,JSON data any of our values can be strings. Dialogue: 0,0:07:15.04,0:07:16.06,Default,,0000,0000,0000,,Now, as I mentioned, there are Dialogue: 0,0:07:16.06,0:07:17.10,Default,,0000,0000,0000,,a few values that are Dialogue: 0,0:07:17.10,0:07:20.04,Default,,0000,0000,0000,,sort of reserved words in JSON. Dialogue: 0,0:07:20.04,0:07:22.04,Default,,0000,0000,0000,,For example, true is a Dialogue: 0,0:07:22.04,0:07:24.04,Default,,0000,0000,0000,,reserved word for a bullion value. Dialogue: 0,0:07:24.04,0:07:25.08,Default,,0000,0000,0000,,That means we don't need to Dialogue: 0,0:07:25.08,0:07:27.02,Default,,0000,0000,0000,,quote it because it's actually Dialogue: 0,0:07:27.02,0:07:28.09,Default,,0000,0000,0000,,its own special type of value. Dialogue: 0,0:07:28.09,0:07:30.04,Default,,0000,0000,0000,,And so is false. Dialogue: 0,0:07:30.04,0:07:32.03,Default,,0000,0000,0000,,And the third one is null, Dialogue: 0,0:07:32.03,0:07:35.00,Default,,0000,0000,0000,,so there's a built-in concept of null. Dialogue: 0,0:07:35.00,0:07:36.06,Default,,0000,0000,0000,,Now, if we wanted to Dialogue: 0,0:07:36.06,0:07:38.02,Default,,0000,0000,0000,,use nil for whatever reason Dialogue: 0,0:07:38.02,0:07:39.06,Default,,0000,0000,0000,,instead of null, well, now Dialogue: 0,0:07:39.06,0:07:40.01,Default,,0000,0000,0000,,we're going to get an error because Dialogue: 0,0:07:40.01,0:07:42.01,Default,,0000,0000,0000,,nil is not a reserved word, Dialogue: 0,0:07:42.01,0:07:43.05,Default,,0000,0000,0000,,and if we really wanted nil Dialogue: 0,0:07:43.05,0:07:47.09,Default,,0000,0000,0000,,then we would need to actually make it a quoted string. Dialogue: 0,0:07:47.09,0:07:50.02,Default,,0000,0000,0000,,Now, let's take a look inside our author list. Dialogue: 0,0:07:50.02,0:07:51.02,Default,,0000,0000,0000,,And I'm going to show you Dialogue: 0,0:07:51.02,0:07:52.01,Default,,0000,0000,0000,,that arrays do not have Dialogue: 0,0:07:52.01,0:07:54.01,Default,,0000,0000,0000,,to have the same type of Dialogue: 0,0:07:54.01,0:07:56.04,Default,,0000,0000,0000,,value for every element in the array. Dialogue: 0,0:07:56.04,0:07:58.00,Default,,0000,0000,0000,,So here we have a homogeneous Dialogue: 0,0:07:58.00,0:07:59.07,Default,,0000,0000,0000,,list of authors. Both of them Dialogue: 0,0:07:59.07,0:08:01.02,Default,,0000,0000,0000,,are objects with a first Dialogue: 0,0:08:01.02,0:08:02.02,Default,,0000,0000,0000,,name and a last name as Dialogue: 0,0:08:02.02,0:08:04.03,Default,,0000,0000,0000,,separate label-value pairs, Dialogue: 0,0:08:04.03,0:08:05.01,Default,,0000,0000,0000,,but if I change that Dialogue: 0,0:08:05.01,0:08:07.10,Default,,0000,0000,0000,,first one, the entire value Dialogue: 0,0:08:07.10,0:08:09.05,Default,,0000,0000,0000,,to be, instead of a Dialogue: 0,0:08:09.05,0:08:11.03,Default,,0000,0000,0000,,composite one, simply the string, Dialogue: 0,0:08:11.03,0:08:13.03,Default,,0000,0000,0000,,Jefferey Ullman. Oops, sorry Dialogue: 0,0:08:13.03,0:08:15.07,Default,,0000,0000,0000,,about my typing there, and that Dialogue: 0,0:08:15.07,0:08:17.00,Default,,0000,0000,0000,,is not an error, it Dialogue: 0,0:08:17.00,0:08:18.08,Default,,0000,0000,0000,,is allowed to have a string, Dialogue: 0,0:08:18.08,0:08:20.00,Default,,0000,0000,0000,,and then a composite object. Dialogue: 0,0:08:20.00,0:08:22.09,Default,,0000,0000,0000,,And we could even have an array, and anything we want. Dialogue: 0,0:08:22.09,0:08:24.00,Default,,0000,0000,0000,,In an array, when you Dialogue: 0,0:08:24.00,0:08:25.04,Default,,0000,0000,0000,,have a list of values, all Dialogue: 0,0:08:25.04,0:08:26.07,Default,,0000,0000,0000,,you need is for each one Dialogue: 0,0:08:26.07,0:08:30.02,Default,,0000,0000,0000,,to be syntactically a correct value in JSON. Dialogue: 0,0:08:30.02,0:08:32.00,Default,,0000,0000,0000,,Now let's go visit our magazines Dialogue: 0,0:08:32.00,0:08:33.01,Default,,0000,0000,0000,,for a moment here and let Dialogue: 0,0:08:33.01,0:08:35.07,Default,,0000,0000,0000,,me show that empty objects are okay. Dialogue: 0,0:08:35.07,0:08:37.08,Default,,0000,0000,0000,,So a list of label Dialogue: 0,0:08:37.08,0:08:41.05,Default,,0000,0000,0000,,value pairs, comprising an object, can be the empty list. Dialogue: 0,0:08:41.05,0:08:42.10,Default,,0000,0000,0000,,And so now I've turned this magazine Dialogue: 0,0:08:42.10,0:08:44.06,Default,,0000,0000,0000,,into having no information about Dialogue: 0,0:08:44.06,0:08:46.04,Default,,0000,0000,0000,,it, but that is legal in JSON. Dialogue: 0,0:08:46.04,0:08:50.09,Default,,0000,0000,0000,,And similarly, arrays are allowed to be of zero length. Dialogue: 0,0:08:50.09,0:08:52.04,Default,,0000,0000,0000,,So I can take these authors Dialogue: 0,0:08:52.04,0:08:53.04,Default,,0000,0000,0000,,here and I can just take Dialogue: 0,0:08:53.04,0:08:54.08,Default,,0000,0000,0000,,out all of the authors, and Dialogue: 0,0:08:54.08,0:08:58.00,Default,,0000,0000,0000,,make that an empty list, but that's still valid JSON. Dialogue: 0,0:08:58.00,0:09:01.09,Default,,0000,0000,0000,,Now, what if I took this array out altogether? Dialogue: 0,0:09:01.09,0:09:02.10,Default,,0000,0000,0000,,In that case, now we Dialogue: 0,0:09:02.10,0:09:04.04,Default,,0000,0000,0000,,have an error because this is Dialogue: 0,0:09:04.04,0:09:05.07,Default,,0000,0000,0000,,an object where we have Dialogue: 0,0:09:05.07,0:09:08.00,Default,,0000,0000,0000,,label-value pairs and every Dialogue: 0,0:09:08.00,0:09:09.03,Default,,0000,0000,0000,,label-value pair has to Dialogue: 0,0:09:09.03,0:09:12.00,Default,,0000,0000,0000,,have both a label and a value. Dialogue: 0,0:09:12.00,0:09:13.09,Default,,0000,0000,0000,,So let's put our array back Dialogue: 0,0:09:13.09,0:09:15.00,Default,,0000,0000,0000,,and we can have anything in Dialogue: 0,0:09:15.00,0:09:16.04,Default,,0000,0000,0000,,there so let's just make it Dialogue: 0,0:09:16.04,0:09:19.02,Default,,0000,0000,0000,,"fu" and that corrects the error. Dialogue: 0,0:09:19.02,0:09:20.00,Default,,0000,0000,0000,,What if we didn't want an Dialogue: 0,0:09:20.00,0:09:21.05,Default,,0000,0000,0000,,array here instead and we Dialogue: 0,0:09:21.05,0:09:24.06,Default,,0000,0000,0000,,tried to make it, say, an object,? Dialogue: 0,0:09:24.06,0:09:26.01,Default,,0000,0000,0000,,Well, we're going to see an Dialogue: 0,0:09:26.01,0:09:28.00,Default,,0000,0000,0000,,error there, because an object Dialogue: 0,0:09:28.00,0:09:29.03,Default,,0000,0000,0000,,as a reminder and this is an Dialogue: 0,0:09:29.03,0:09:30.08,Default,,0000,0000,0000,,easy mistake to make. Objects Dialogue: 0,0:09:30.08,0:09:33.03,Default,,0000,0000,0000,,are always label-value pairs. Dialogue: 0,0:09:33.03,0:09:34.01,Default,,0000,0000,0000,,So if you want just a value, Dialogue: 0,0:09:34.01,0:09:36.01,Default,,0000,0000,0000,,that should be an array if Dialogue: 0,0:09:36.01,0:09:37.06,Default,,0000,0000,0000,,you want an object, then we're Dialogue: 0,0:09:37.06,0:09:39.01,Default,,0000,0000,0000,,talking about a label-value pair, so Dialogue: 0,0:09:39.01,0:09:40.02,Default,,0000,0000,0000,,we can just add "fu" as Dialogue: 0,0:09:40.02,0:09:42.08,Default,,0000,0000,0000,,our value, and then we're all set. Dialogue: 0,0:09:42.08,0:09:46.00,Default,,0000,0000,0000,,So what we've seen so far is syntactic correctness. Dialogue: 0,0:09:46.00,0:09:48.00,Default,,0000,0000,0000,,Again, there's no required Dialogue: 0,0:09:48.00,0:09:50.07,Default,,0000,0000,0000,,uniformity across values in Dialogue: 0,0:09:50.07,0:09:52.10,Default,,0000,0000,0000,,arrays or in the Dialogue: 0,0:09:52.10,0:09:55.01,Default,,0000,0000,0000,,label-value pairs in objects we Dialogue: 0,0:09:55.01,0:09:56.05,Default,,0000,0000,0000,,just need to ensure that Dialogue: 0,0:09:56.05,0:09:57.08,Default,,0000,0000,0000,,all of our values, our basic Dialogue: 0,0:09:57.08,0:09:59.02,Default,,0000,0000,0000,,values, are of the right types, Dialogue: 0,0:09:59.02,0:10:00.04,Default,,0000,0000,0000,,and things like our commas and Dialogue: 0,0:10:00.04,0:10:02.09,Default,,0000,0000,0000,,curly braces are all in place. Dialogue: 0,0:10:02.09,0:10:04.02,Default,,0000,0000,0000,,What we're gonna do next is look Dialogue: 0,0:10:04.02,0:10:05.08,Default,,0000,0000,0000,,at JSON's schema where we Dialogue: 0,0:10:05.08,0:10:08.01,Default,,0000,0000,0000,,have a mechanism for enforcing certain Dialogue: 0,0:10:08.01,0:10:11.08,Default,,0000,0000,0000,,constraints beyond simple syntactic correctness. Dialogue: 0,0:10:11.08,0:10:13.00,Default,,0000,0000,0000,,If you've been very observant, you Dialogue: 0,0:10:13.00,0:10:14.03,Default,,0000,0000,0000,,might even have noticed that we Dialogue: 0,0:10:14.03,0:10:15.05,Default,,0000,0000,0000,,have a second tab up Dialogue: 0,0:10:15.05,0:10:17.03,Default,,0000,0000,0000,,here in our editor for a Dialogue: 0,0:10:17.03,0:10:18.10,Default,,0000,0000,0000,,second JSON file, and this file Dialogue: 0,0:10:18.10,0:10:20.03,Default,,0000,0000,0000,,is going to be the schema Dialogue: 0,0:10:20.03,0:10:22.08,Default,,0000,0000,0000,,for our bookstore data. We're using Dialogue: 0,0:10:22.08,0:10:25.01,Default,,0000,0000,0000,,JSON schema, and JSON Dialogue: 0,0:10:25.01,0:10:27.01,Default,,0000,0000,0000,,schema, like, XML schema Dialogue: 0,0:10:27.01,0:10:29.00,Default,,0000,0000,0000,,is expressed in the data model itself. Dialogue: 0,0:10:29.00,0:10:31.03,Default,,0000,0000,0000,,So, our schema description for Dialogue: 0,0:10:31.03,0:10:33.02,Default,,0000,0000,0000,,this JSON data is itself Dialogue: 0,0:10:33.02,0:10:35.04,Default,,0000,0000,0000,,JSON data, and here it is. Dialogue: 0,0:10:35.04,0:10:37.01,Default,,0000,0000,0000,,And it's going to take a bit of time to explain. Dialogue: 0,0:10:37.01,0:10:37.10,Default,,0000,0000,0000,,Now the first thing that you might Dialogue: 0,0:10:37.10,0:10:39.04,Default,,0000,0000,0000,,notice is wow, the schema Dialogue: 0,0:10:39.04,0:10:41.00,Default,,0000,0000,0000,,looks more complicated and in Dialogue: 0,0:10:41.00,0:10:43.05,Default,,0000,0000,0000,,fact longer than the data itself. Dialogue: 0,0:10:43.05,0:10:47.01,Default,,0000,0000,0000,,Well, that is true, but that's mostly because our data file is tiny. Dialogue: 0,0:10:47.01,0:10:49.02,Default,,0000,0000,0000,,So, if we had thousands, you know, tens Dialogue: 0,0:10:49.02,0:10:51.05,Default,,0000,0000,0000,,of thousands of books and magazines, Dialogue: 0,0:10:51.05,0:10:53.01,Default,,0000,0000,0000,,our schema file wouldn't Dialogue: 0,0:10:53.01,0:10:54.03,Default,,0000,0000,0000,,change, but our data file would Dialogue: 0,0:10:54.03,0:10:57.06,Default,,0000,0000,0000,,be much longer and that's the typical case, in reality. Dialogue: 0,0:10:57.06,0:10:58.08,Default,,0000,0000,0000,,Now, this video is not a Dialogue: 0,0:10:58.08,0:11:01.00,Default,,0000,0000,0000,,complete tutorial about JSON's schema. Dialogue: 0,0:11:01.00,0:11:02.08,Default,,0000,0000,0000,,There's many constructs in JSON's Dialogue: 0,0:11:02.08,0:11:04.06,Default,,0000,0000,0000,,schema that weren't needed to Dialogue: 0,0:11:04.06,0:11:06.08,Default,,0000,0000,0000,,describe the bookstore data, for example. Dialogue: 0,0:11:06.08,0:11:08.05,Default,,0000,0000,0000,,And even this file here, Dialogue: 0,0:11:08.05,0:11:11.06,Default,,0000,0000,0000,,I'm not gonna go through every detail of it right here. Dialogue: 0,0:11:11.06,0:11:12.07,Default,,0000,0000,0000,,You can download the file and Dialogue: 0,0:11:12.07,0:11:15.02,Default,,0000,0000,0000,,take a look, read a little more about JSON schema. Dialogue: 0,0:11:15.02,0:11:16.03,Default,,0000,0000,0000,,I'm just going to give the Dialogue: 0,0:11:16.03,0:11:17.07,Default,,0000,0000,0000,,flavor of the schema Dialogue: 0,0:11:17.07,0:11:19.03,Default,,0000,0000,0000,,specification and then we're Dialogue: 0,0:11:19.03,0:11:20.09,Default,,0000,0000,0000,,going to work with validating the data Dialogue: 0,0:11:20.09,0:11:24.00,Default,,0000,0000,0000,,itself to see how the schema and data work together. Dialogue: 0,0:11:24.00,0:11:28.00,Default,,0000,0000,0000,,But to give you the flavor here, let's go through at least some portions of the schema. Dialogue: 0,0:11:28.00,0:11:29.06,Default,,0000,0000,0000,,So, in some sense, Dialogue: 0,0:11:29.06,0:11:31.06,Default,,0000,0000,0000,,the structure of the schema file Dialogue: 0,0:11:31.06,0:11:34.06,Default,,0000,0000,0000,,reflects the structure of the data file that it's describing. Dialogue: 0,0:11:34.06,0:11:37.02,Default,,0000,0000,0000,,So, the outermost constructs in Dialogue: 0,0:11:37.02,0:11:38.03,Default,,0000,0000,0000,,the schema file are the Dialogue: 0,0:11:38.03,0:11:39.06,Default,,0000,0000,0000,,outermost in the data file and Dialogue: 0,0:11:39.06,0:11:42.05,Default,,0000,0000,0000,,as we nest it parallels the nesting. Dialogue: 0,0:11:42.05,0:11:43.07,Default,,0000,0000,0000,,Let me just show a little Dialogue: 0,0:11:43.07,0:11:48.05,Default,,0000,0000,0000,,bit here, we'll probably look at most of it in the context of validation. Dialogue: 0,0:11:48.05,0:11:52.07,Default,,0000,0000,0000,,So, we see here that our outermost construct in our data file is an object. Dialogue: 0,0:11:52.07,0:11:53.08,Default,,0000,0000,0000,,And that's told to us, Dialogue: 0,0:11:53.08,0:11:55.01,Default,,0000,0000,0000,,because we have "type" as Dialogue: 0,0:11:55.01,0:11:57.03,Default,,0000,0000,0000,,one of our built-in labels for the schema. Dialogue: 0,0:11:57.03,0:11:58.05,Default,,0000,0000,0000,,So we we have an Dialogue: 0,0:11:58.05,0:12:00.06,Default,,0000,0000,0000,,object with two properties, as Dialogue: 0,0:12:00.06,0:12:02.06,Default,,0000,0000,0000,,we can see here, the book's property Dialogue: 0,0:12:02.06,0:12:04.06,Default,,0000,0000,0000,,and the magazine's property. Dialogue: 0,0:12:04.06,0:12:05.08,Default,,0000,0000,0000,,And I use the word Dialogue: 0,0:12:05.08,0:12:07.09,Default,,0000,0000,0000,,"labels" frequently for label-value Dialogue: 0,0:12:07.09,0:12:11.06,Default,,0000,0000,0000,,pairs, that's synonymous with property value pairs. Dialogue: 0,0:12:11.06,0:12:13.06,Default,,0000,0000,0000,,Then inside the books property Dialogue: 0,0:12:13.06,0:12:15.00,Default,,0000,0000,0000,,for example, we see that Dialogue: 0,0:12:15.00,0:12:16.06,Default,,0000,0000,0000,,the type of that is array, Dialogue: 0,0:12:16.06,0:12:19.02,Default,,0000,0000,0000,,so we've got a label-value pair where the value is an array. Dialogue: 0,0:12:19.02,0:12:22.04,Default,,0000,0000,0000,,And then we follow the nesting and see that it's an array of objects. Dialogue: 0,0:12:22.04,0:12:24.02,Default,,0000,0000,0000,,And we go further down and we Dialogue: 0,0:12:24.02,0:12:26.00,Default,,0000,0000,0000,,see the different label-value pairs Dialogue: 0,0:12:26.00,0:12:27.05,Default,,0000,0000,0000,,of the object that make up Dialogue: 0,0:12:27.05,0:12:31.00,Default,,0000,0000,0000,,the books and nesting further into the authors and so on. Dialogue: 0,0:12:31.00,0:12:32.10,Default,,0000,0000,0000,,We see similarly for magazines Dialogue: 0,0:12:32.10,0:12:34.08,Default,,0000,0000,0000,,that the value of the Dialogue: 0,0:12:34.08,0:12:36.02,Default,,0000,0000,0000,,a label-value pair for Dialogue: 0,0:12:36.02,0:12:37.09,Default,,0000,0000,0000,,magazines is an array, and Dialogue: 0,0:12:37.09,0:12:41.00,Default,,0000,0000,0000,,that array consists of objects with further nesting. Dialogue: 0,0:12:41.00,0:12:42.02,Default,,0000,0000,0000,,So what we're looking at here is Dialogue: 0,0:12:42.02,0:12:45.06,Default,,0000,0000,0000,,an online JSON schema validator. We have two windows. Dialogue: 0,0:12:45.06,0:12:46.05,Default,,0000,0000,0000,,On the left we have our Dialogue: 0,0:12:46.05,0:12:47.06,Default,,0000,0000,0000,,schema and on the Dialogue: 0,0:12:47.06,0:12:49.01,Default,,0000,0000,0000,,right we have our data, and Dialogue: 0,0:12:49.01,0:12:50.06,Default,,0000,0000,0000,,this is exactly the same data Dialogue: 0,0:12:50.06,0:12:54.00,Default,,0000,0000,0000,,file and schema file that we were looking at earlier. Dialogue: 0,0:12:54.00,0:12:55.07,Default,,0000,0000,0000,,If we hit the validate button, Dialogue: 0,0:12:55.07,0:12:58.02,Default,,0000,0000,0000,,hopefully everything should work and it does. Dialogue: 0,0:12:58.02,0:12:59.03,Default,,0000,0000,0000,,This tells us that the Dialogue: 0,0:12:59.03,0:13:03.00,Default,,0000,0000,0000,,JSON data is valid with respect to the schema. Dialogue: 0,0:13:03.00,0:13:04.06,Default,,0000,0000,0000,,Now, this system will of Dialogue: 0,0:13:04.06,0:13:06.05,Default,,0000,0000,0000,,course find basic syntactic errors Dialogue: 0,0:13:06.05,0:13:07.08,Default,,0000,0000,0000,,so I can take away a comma Dialogue: 0,0:13:07.08,0:13:09.00,Default,,0000,0000,0000,,just like I did before and Dialogue: 0,0:13:09.00,0:13:10.04,Default,,0000,0000,0000,,when I validate I'll get a Dialogue: 0,0:13:10.04,0:13:13.03,Default,,0000,0000,0000,,parsing error that really has nothing to do with the schema. Dialogue: 0,0:13:13.03,0:13:14.00,Default,,0000,0000,0000,,What I'm going to focus on Dialogue: 0,0:13:14.00,0:13:16.05,Default,,0000,0000,0000,,now is actually validating Dialogue: 0,0:13:16.05,0:13:18.04,Default,,0000,0000,0000,,semantic correctness of the Jason Dialogue: 0,0:13:18.04,0:13:19.08,Default,,0000,0000,0000,,with respect back to the constructs Dialogue: 0,0:13:19.08,0:13:21.04,Default,,0000,0000,0000,,that we've specified in this schema. Dialogue: 0,0:13:21.04,0:13:25.03,Default,,0000,0000,0000,,Let me first put that comma back so we start with a valid file. Dialogue: 0,0:13:25.03,0:13:26.08,Default,,0000,0000,0000,,So, the first thing I'll show is Dialogue: 0,0:13:26.08,0:13:28.04,Default,,0000,0000,0000,,the ability to constrain basic Dialogue: 0,0:13:28.04,0:13:29.07,Default,,0000,0000,0000,,types, and then the ability Dialogue: 0,0:13:29.07,0:13:32.02,Default,,0000,0000,0000,,to constrain the range of values of those basic types. Dialogue: 0,0:13:32.02,0:13:34.05,Default,,0000,0000,0000,,And let's focus on price. Dialogue: 0,0:13:34.05,0:13:35.06,Default,,0000,0000,0000,,So here we're talking about the Dialogue: 0,0:13:35.06,0:13:37.08,Default,,0000,0000,0000,,price property inside books and Dialogue: 0,0:13:37.08,0:13:39.06,Default,,0000,0000,0000,,we specify in our schema Dialogue: 0,0:13:39.06,0:13:42.00,Default,,0000,0000,0000,,that the type of the price must be an integer. Dialogue: 0,0:13:42.00,0:13:44.00,Default,,0000,0000,0000,,So, for example, if our Dialogue: 0,0:13:44.00,0:13:46.02,Default,,0000,0000,0000,,price were instead a string Dialogue: 0,0:13:46.02,0:13:47.03,Default,,0000,0000,0000,,and we went ahead and try Dialogue: 0,0:13:47.03,0:13:49.10,Default,,0000,0000,0000,,to validate that we would get an error. Dialogue: 0,0:13:49.10,0:13:51.00,Default,,0000,0000,0000,,Let's make it back into an Dialogue: 0,0:13:51.00,0:13:53.07,Default,,0000,0000,0000,,integer but let's make Dialogue: 0,0:13:53.07,0:13:56.01,Default,,0000,0000,0000,,it into the integer 300 now instead of 100. Dialogue: 0,0:13:56.01,0:13:58.06,Default,,0000,0000,0000,,And why am I doing that? Dialogue: 0,0:13:58.06,0:14:00.04,Default,,0000,0000,0000,,Because the JSON schema also Dialogue: 0,0:14:00.04,0:14:01.10,Default,,0000,0000,0000,,lets me constrain the range of Dialogue: 0,0:14:01.10,0:14:05.01,Default,,0000,0000,0000,,values that are allowed if we have a numeric value. Dialogue: 0,0:14:05.01,0:14:06.07,Default,,0000,0000,0000,,So, not only in price did I Dialogue: 0,0:14:06.07,0:14:08.03,Default,,0000,0000,0000,,say that it's an integer but Dialogue: 0,0:14:08.03,0:14:09.05,Default,,0000,0000,0000,,I also said that it Dialogue: 0,0:14:09.05,0:14:11.01,Default,,0000,0000,0000,,has a minimum and maximum value, Dialogue: 0,0:14:11.01,0:14:13.02,Default,,0000,0000,0000,,the integer of prices must Dialogue: 0,0:14:13.02,0:14:15.04,Default,,0000,0000,0000,,be between 0 and 200. Dialogue: 0,0:14:15.04,0:14:16.04,Default,,0000,0000,0000,,So, if I try to make Dialogue: 0,0:14:16.04,0:14:18.02,Default,,0000,0000,0000,,the price of 300, and I Dialogue: 0,0:14:18.02,0:14:20.00,Default,,0000,0000,0000,,validate, I'm again getting an error. Dialogue: 0,0:14:20.00,0:14:21.09,Default,,0000,0000,0000,,Now it's not a type error, Dialogue: 0,0:14:21.09,0:14:23.00,Default,,0000,0000,0000,,but it's an error that my Dialogue: 0,0:14:23.00,0:14:26.03,Default,,0000,0000,0000,,integer was outside of the allowed range. Dialogue: 0,0:14:26.03,0:14:27.05,Default,,0000,0000,0000,,I've put the price back to Dialogue: 0,0:14:27.05,0:14:28.08,Default,,0000,0000,0000,,a hundred, and now let's Dialogue: 0,0:14:28.08,0:14:32.02,Default,,0000,0000,0000,,look at constraints on string values. Dialogue: 0,0:14:32.02,0:14:33.05,Default,,0000,0000,0000,,JSON schema actually has Dialogue: 0,0:14:33.05,0:14:35.02,Default,,0000,0000,0000,,a little pattern matching language that Dialogue: 0,0:14:35.02,0:14:36.06,Default,,0000,0000,0000,,can be used to constrain the Dialogue: 0,0:14:36.06,0:14:40.02,Default,,0000,0000,0000,,allowable strings for a specific type of value. Dialogue: 0,0:14:40.02,0:14:43.04,Default,,0000,0000,0000,,We'll look at ISBN number here as an example of that. Dialogue: 0,0:14:43.04,0:14:45.02,Default,,0000,0000,0000,,We've said that ISBN is Dialogue: 0,0:14:45.02,0:14:47.01,Default,,0000,0000,0000,,of type string, and then Dialogue: 0,0:14:47.01,0:14:48.06,Default,,0000,0000,0000,,we've further constrained in the Dialogue: 0,0:14:48.06,0:14:50.00,Default,,0000,0000,0000,,schema that the string values for Dialogue: 0,0:14:50.00,0:14:52.07,Default,,0000,0000,0000,,ISBN must satisfy a certain pattern. Dialogue: 0,0:14:52.07,0:14:56.02,Default,,0000,0000,0000,,I'm not gonna go into the details of this pattern-matching language. Dialogue: 0,0:14:56.02,0:14:57.07,Default,,0000,0000,0000,,I'm just gonna give an example. Dialogue: 0,0:14:57.07,0:14:59.01,Default,,0000,0000,0000,,And in fact, this entire demo is Dialogue: 0,0:14:59.01,0:15:00.06,Default,,0000,0000,0000,,really just an example lots of Dialogue: 0,0:15:00.06,0:15:03.04,Default,,0000,0000,0000,,things in JSON's schema that we're not seeing. Dialogue: 0,0:15:03.04,0:15:05.04,Default,,0000,0000,0000,,What this pattern here says is Dialogue: 0,0:15:05.04,0:15:06.10,Default,,0000,0000,0000,,that the string value for Dialogue: 0,0:15:06.10,0:15:08.09,Default,,0000,0000,0000,,ISBN must start with Dialogue: 0,0:15:08.09,0:15:13.01,Default,,0000,0000,0000,,the four characters ISBN and then can be followed by anything else. Dialogue: 0,0:15:13.01,0:15:14.01,Default,,0000,0000,0000,,So, if we go over to our Dialogue: 0,0:15:14.01,0:15:15.04,Default,,0000,0000,0000,,data and we look at Dialogue: 0,0:15:15.04,0:15:17.01,Default,,0000,0000,0000,,the ISBN number here and Dialogue: 0,0:15:17.01,0:15:18.00,Default,,0000,0000,0000,,say we have a typo, we Dialogue: 0,0:15:18.00,0:15:20.08,Default,,0000,0000,0000,,forgot the "I" and we try to validate. Dialogue: 0,0:15:20.08,0:15:22.04,Default,,0000,0000,0000,,Then we'll see that our data Dialogue: 0,0:15:22.04,0:15:25.07,Default,,0000,0000,0000,,no longer matches our schema specification. Dialogue: 0,0:15:25.07,0:15:29.04,Default,,0000,0000,0000,,Now let's look at some other constraints we can specify in JSON's schema. Dialogue: 0,0:15:29.04,0:15:32.02,Default,,0000,0000,0000,,We can constrain the number of elements in an array. Dialogue: 0,0:15:32.02,0:15:35.00,Default,,0000,0000,0000,,We can give a minimum or maximum or both. Dialogue: 0,0:15:35.00,0:15:38.01,Default,,0000,0000,0000,,And I've done that here in the context of the authors array. Dialogue: 0,0:15:38.01,0:15:39.07,Default,,0000,0000,0000,,Remember the authors are Dialogue: 0,0:15:39.07,0:15:40.07,Default,,0000,0000,0000,,an array that's a list of Dialogue: 0,0:15:40.07,0:15:42.09,Default,,0000,0000,0000,,objects and here I've said that Dialogue: 0,0:15:42.09,0:15:44.01,Default,,0000,0000,0000,,we have a minimum number of Dialogue: 0,0:15:44.01,0:15:45.04,Default,,0000,0000,0000,,items of 1 and a Dialogue: 0,0:15:45.04,0:15:46.08,Default,,0000,0000,0000,,maximum number items of 10. Dialogue: 0,0:15:46.08,0:15:48.04,Default,,0000,0000,0000,,In other words, every book Dialogue: 0,0:15:48.04,0:15:51.04,Default,,0000,0000,0000,,has to have between one and ten authors. Dialogue: 0,0:15:51.04,0:15:53.02,Default,,0000,0000,0000,,So let's try, for example, Dialogue: 0,0:15:53.02,0:15:56.02,Default,,0000,0000,0000,,taking out all of our authors here in our first book. Dialogue: 0,0:15:56.02,0:15:57.08,Default,,0000,0000,0000,,We actually looked at this before in terms Dialogue: 0,0:15:57.08,0:15:59.03,Default,,0000,0000,0000,,of syntactic validity, and it Dialogue: 0,0:15:59.03,0:16:01.04,Default,,0000,0000,0000,,was perfectly valid to have an empty array. Dialogue: 0,0:16:01.04,0:16:02.09,Default,,0000,0000,0000,,But when we try to validate Dialogue: 0,0:16:02.09,0:16:03.09,Default,,0000,0000,0000,,now we do get an Dialogue: 0,0:16:03.09,0:16:05.01,Default,,0000,0000,0000,,error, and the reason is Dialogue: 0,0:16:05.01,0:16:06.02,Default,,0000,0000,0000,,that we said that we needed Dialogue: 0,0:16:06.02,0:16:10.05,Default,,0000,0000,0000,,between one and ten array elements in the case of authors. Dialogue: 0,0:16:10.05,0:16:12.00,Default,,0000,0000,0000,,Now let's fix that, Dialogue: 0,0:16:12.00,0:16:13.05,Default,,0000,0000,0000,,not by putting our authors back Dialogue: 0,0:16:13.05,0:16:14.09,Default,,0000,0000,0000,,but let's say we actually decide Dialogue: 0,0:16:14.09,0:16:17.06,Default,,0000,0000,0000,,we would like to be able to have books that have no authors. Dialogue: 0,0:16:17.06,0:16:19.01,Default,,0000,0000,0000,,So, we can simply fix Dialogue: 0,0:16:19.01,0:16:21.00,Default,,0000,0000,0000,,that by changing that minimum Dialogue: 0,0:16:21.00,0:16:23.00,Default,,0000,0000,0000,,item to zero and that Dialogue: 0,0:16:23.00,0:16:24.10,Default,,0000,0000,0000,,makes our data valid again and Dialogue: 0,0:16:24.10,0:16:26.03,Default,,0000,0000,0000,,in fact, we could actually take that Dialogue: 0,0:16:26.03,0:16:28.05,Default,,0000,0000,0000,,minimum constraint out all together, Dialogue: 0,0:16:28.05,0:16:32.08,Default,,0000,0000,0000,,and if we do that our data is still going to be valid. Dialogue: 0,0:16:32.08,0:16:33.01,Default,,0000,0000,0000,,Now let's see what happens when we Dialogue: 0,0:16:33.01,0:16:36.09,Default,,0000,0000,0000,,add something to our data that isn't mentioned in the schema. Dialogue: 0,0:16:36.09,0:16:38.03,Default,,0000,0000,0000,,If you look carefully you'll see Dialogue: 0,0:16:38.03,0:16:39.04,Default,,0000,0000,0000,,that everything that we have Dialogue: 0,0:16:39.04,0:16:42.02,Default,,0000,0000,0000,,in the data so far has been specified in the schema. Dialogue: 0,0:16:42.02,0:16:43.08,Default,,0000,0000,0000,,Let's say we come along Dialogue: 0,0:16:43.08,0:16:46.03,Default,,0000,0000,0000,,and decide were gonna also have ratings for our books. Dialogue: 0,0:16:46.03,0:16:47.09,Default,,0000,0000,0000,,So let's add here a Dialogue: 0,0:16:47.09,0:16:51.08,Default,,0000,0000,0000,,rating label property with the value 5. Dialogue: 0,0:16:51.08,0:16:53.06,Default,,0000,0000,0000,,We go ahead and validate, you Dialogue: 0,0:16:53.06,0:16:54.07,Default,,0000,0000,0000,,probaly think it's not going to Dialogue: 0,0:16:54.07,0:16:57.04,Default,,0000,0000,0000,,validate properly but actually it did. Dialogue: 0,0:16:57.04,0:16:59.03,Default,,0000,0000,0000,,The definition of JSON Dialogue: 0,0:16:59.03,0:17:00.09,Default,,0000,0000,0000,,schema that it can constrain things by Dialogue: 0,0:17:00.09,0:17:02.03,Default,,0000,0000,0000,,describing them but you Dialogue: 0,0:17:02.03,0:17:04.01,Default,,0000,0000,0000,,can also have components in Dialogue: 0,0:17:04.01,0:17:06.01,Default,,0000,0000,0000,,the data that aren't present in this schema. Dialogue: 0,0:17:06.01,0:17:08.03,Default,,0000,0000,0000,,If we want to insist Dialogue: 0,0:17:08.03,0:17:10.05,Default,,0000,0000,0000,,that every property that is Dialogue: 0,0:17:10.05,0:17:11.07,Default,,0000,0000,0000,,present in the data is Dialogue: 0,0:17:11.07,0:17:12.01,Default,,0000,0000,0000,,also described in this Dialogue: 0,0:17:12.01,0:17:14.00,Default,,0000,0000,0000,,schema, then we can Dialogue: 0,0:17:14.00,0:17:17.01,Default,,0000,0000,0000,,actually add a constraint to the schema that tells us that. Dialogue: 0,0:17:17.01,0:17:20.07,Default,,0000,0000,0000,,Specifically, under the object Dialogue: 0,0:17:20.07,0:17:22.04,Default,,0000,0000,0000,,here, we can put in Dialogue: 0,0:17:22.04,0:17:24.01,Default,,0000,0000,0000,,a special flag which itself Dialogue: 0,0:17:24.01,0:17:27.01,Default,,0000,0000,0000,,is specified as a label called additional properties. Dialogue: 0,0:17:27.01,0:17:29.02,Default,,0000,0000,0000,,And this flag if we Dialogue: 0,0:17:29.02,0:17:31.04,Default,,0000,0000,0000,,set it to false and remember Dialogue: 0,0:17:31.04,0:17:32.10,Default,,0000,0000,0000,,false can is actually a keyword Dialogue: 0,0:17:32.10,0:17:34.05,Default,,0000,0000,0000,,in json's schema, tells us Dialogue: 0,0:17:34.05,0:17:36.02,Default,,0000,0000,0000,,that in our data we're not Dialogue: 0,0:17:36.02,0:17:37.08,Default,,0000,0000,0000,,allowed to have any properties Dialogue: 0,0:17:37.08,0:17:40.05,Default,,0000,0000,0000,,beyond those that are specified in the schema. Dialogue: 0,0:17:40.05,0:17:41.09,Default,,0000,0000,0000,,So now we validate and we Dialogue: 0,0:17:41.09,0:17:43.06,Default,,0000,0000,0000,,get an error, because the property Dialogue: 0,0:17:43.06,0:17:46.02,Default,,0000,0000,0000,,rating hasn't been defined in the schema. Dialogue: 0,0:17:46.02,0:17:48.05,Default,,0000,0000,0000,,If additional properties is missing, Dialogue: 0,0:17:48.05,0:17:50.02,Default,,0000,0000,0000,,or have the default value Dialogue: 0,0:17:50.02,0:17:53.08,Default,,0000,0000,0000,,of "true", then the validation goes through. Dialogue: 0,0:17:53.08,0:17:56.10,Default,,0000,0000,0000,,Now lets take a look at our authors that are still here. Dialogue: 0,0:17:56.10,0:17:58.00,Default,,0000,0000,0000,,Let's suppose that we don't Dialogue: 0,0:17:58.00,0:18:01.05,Default,,0000,0000,0000,,have a first name for our middle author here. Dialogue: 0,0:18:01.05,0:18:02.09,Default,,0000,0000,0000,,If we take that away and Dialogue: 0,0:18:02.09,0:18:04.06,Default,,0000,0000,0000,,we try to validate, we do Dialogue: 0,0:18:04.06,0:18:06.06,Default,,0000,0000,0000,,get an error, because we specified Dialogue: 0,0:18:06.06,0:18:08.04,Default,,0000,0000,0000,,in our schema and it's right Dialogue: 0,0:18:08.04,0:18:11.08,Default,,0000,0000,0000,,down here--that author-objects must Dialogue: 0,0:18:11.08,0:18:14.08,Default,,0000,0000,0000,,have both a first name and a last name. Dialogue: 0,0:18:14.08,0:18:16.03,Default,,0000,0000,0000,,It turns out that we can Dialogue: 0,0:18:16.03,0:18:20.02,Default,,0000,0000,0000,,specify for every property that the property is optional. Dialogue: 0,0:18:20.02,0:18:21.08,Default,,0000,0000,0000,,So, we can add to the Dialogue: 0,0:18:21.08,0:18:23.04,Default,,0000,0000,0000,,description of the first Dialogue: 0,0:18:23.04,0:18:24.06,Default,,0000,0000,0000,,name, not only that the Dialogue: 0,0:18:24.06,0:18:26.04,Default,,0000,0000,0000,,type is a string but that that Dialogue: 0,0:18:26.04,0:18:27.08,Default,,0000,0000,0000,,property is optional so we Dialogue: 0,0:18:27.08,0:18:31.02,Default,,0000,0000,0000,,say optional, true. Dialogue: 0,0:18:31.02,0:18:34.04,Default,,0000,0000,0000,,Now let's validate, and now we're in good shape. Dialogue: 0,0:18:34.04,0:18:35.02,Default,,0000,0000,0000,,Now, let's take a look Dialogue: 0,0:18:35.02,0:18:36.01,Default,,0000,0000,0000,,at what happens when we have Dialogue: 0,0:18:36.01,0:18:37.09,Default,,0000,0000,0000,,object that has more than Dialogue: 0,0:18:37.09,0:18:41.02,Default,,0000,0000,0000,,one instance of the same label or same property. Dialogue: 0,0:18:41.02,0:18:43.02,Default,,0000,0000,0000,,So let's suppose, for example, in Dialogue: 0,0:18:43.02,0:18:45.02,Default,,0000,0000,0000,,our magazine, the magazine Dialogue: 0,0:18:45.02,0:18:46.06,Default,,0000,0000,0000,,has two different years, 2009 and 2011. Dialogue: 0,0:18:46.06,0:18:52.04,Default,,0000,0000,0000,,This is syntactically valid, JSON, Dialogue: 0,0:18:52.04,0:18:55.08,Default,,0000,0000,0000,,it meets the structure of having a list of label-value pairs. Dialogue: 0,0:18:55.08,0:18:57.02,Default,,0000,0000,0000,,When we validate it, we Dialogue: 0,0:18:57.02,0:19:00.02,Default,,0000,0000,0000,,see that we can't add a second property, year. Dialogue: 0,0:19:00.02,0:19:02.07,Default,,0000,0000,0000,,So this validator doesn't permit Dialogue: 0,0:19:02.07,0:19:04.01,Default,,0000,0000,0000,,two copies of the same Dialogue: 0,0:19:04.01,0:19:05.09,Default,,0000,0000,0000,,property, and it's actually kind Dialogue: 0,0:19:05.09,0:19:07.02,Default,,0000,0000,0000,,of a parsing thing and not Dialogue: 0,0:19:07.02,0:19:09.00,Default,,0000,0000,0000,,so much related to JSON's schema. Dialogue: 0,0:19:09.00,0:19:12.05,Default,,0000,0000,0000,,Many parsers actually do enforce Dialogue: 0,0:19:12.05,0:19:14.02,Default,,0000,0000,0000,,that labels or properties need Dialogue: 0,0:19:14.02,0:19:15.07,Default,,0000,0000,0000,,to be unique within objects, even Dialogue: 0,0:19:15.07,0:19:18.00,Default,,0000,0000,0000,,though technically syntactically correct Dialogue: 0,0:19:18.00,0:19:20.00,Default,,0000,0000,0000,,JSON does allow multiple copies. Dialogue: 0,0:19:20.00,0:19:22.03,Default,,0000,0000,0000,,So that's just something to remember, Dialogue: 0,0:19:22.03,0:19:23.09,Default,,0000,0000,0000,,the typical use of objects is Dialogue: 0,0:19:23.09,0:19:26.02,Default,,0000,0000,0000,,to have unique labels, sometimes Dialogue: 0,0:19:26.02,0:19:30.00,Default,,0000,0000,0000,,are even called keys of which evokes a concept of them unique. Dialogue: 0,0:19:30.00,0:19:32.00,Default,,0000,0000,0000,,So typically they are unique. Dialogue: 0,0:19:32.00,0:19:34.02,Default,,0000,0000,0000,,They don't have to be for syntactic validity. Dialogue: 0,0:19:34.02,0:19:35.05,Default,,0000,0000,0000,,Usually when you wanna have Dialogue: 0,0:19:35.05,0:19:39.04,Default,,0000,0000,0000,,repeated values, it actually makes more sense to create an array. Dialogue: 0,0:19:39.04,0:19:41.08,Default,,0000,0000,0000,,I've taken away the second year in order to make the JSON valid again. Dialogue: 0,0:19:41.08,0:19:44.07,Default,,0000,0000,0000,,Now let's take a look at months. Dialogue: 0,0:19:44.07,0:19:46.06,Default,,0000,0000,0000,,I've used months to illustrate Dialogue: 0,0:19:46.06,0:19:48.09,Default,,0000,0000,0000,,the enumeration constraint so we Dialogue: 0,0:19:48.09,0:19:50.01,Default,,0000,0000,0000,,saw that we could constrain the Dialogue: 0,0:19:50.01,0:19:52.02,Default,,0000,0000,0000,,values of integers, and we Dialogue: 0,0:19:52.02,0:19:54.01,Default,,0000,0000,0000,,saw that we can constrain strings Dialogue: 0,0:19:54.01,0:19:55.05,Default,,0000,0000,0000,,using a pattern, but we can Dialogue: 0,0:19:55.05,0:19:57.00,Default,,0000,0000,0000,,also constrain any type by Dialogue: 0,0:19:57.00,0:19:59.03,Default,,0000,0000,0000,,enumerating the values that are allowed. Dialogue: 0,0:19:59.03,0:20:00.08,Default,,0000,0000,0000,,So, for the month, we've set Dialogue: 0,0:20:00.08,0:20:02.02,Default,,0000,0000,0000,,it a string type which it Dialogue: 0,0:20:02.02,0:20:03.08,Default,,0000,0000,0000,,is but we've further constrained it Dialogue: 0,0:20:03.08,0:20:05.09,Default,,0000,0000,0000,,by saying that string must be Dialogue: 0,0:20:05.09,0:20:08.00,Default,,0000,0000,0000,,either January or February. Dialogue: 0,0:20:08.00,0:20:09.00,Default,,0000,0000,0000,,So, if we try to say Dialogue: 0,0:20:09.00,0:20:14.05,Default,,0000,0000,0000,,put in the string March, we Dialogue: 0,0:20:14.05,0:20:17.03,Default,,0000,0000,0000,,validate and we get the obvious error here. Dialogue: 0,0:20:17.03,0:20:18.06,Default,,0000,0000,0000,,We can fix that by changing the Dialogue: 0,0:20:18.06,0:20:19.09,Default,,0000,0000,0000,,month back, but maybe it Dialogue: 0,0:20:19.09,0:20:21.03,Default,,0000,0000,0000,,makes more sense that March Dialogue: 0,0:20:21.03,0:20:23.00,Default,,0000,0000,0000,,would be part of our enumeration type, Dialogue: 0,0:20:23.00,0:20:24.03,Default,,0000,0000,0000,,so we'll add March to Dialogue: 0,0:20:24.03,0:20:27.06,Default,,0000,0000,0000,,the possible values for months, and now we're good. Dialogue: 0,0:20:27.06,0:20:28.09,Default,,0000,0000,0000,,As a next example, let's take Dialogue: 0,0:20:28.09,0:20:30.01,Default,,0000,0000,0000,,a look at something that we Dialogue: 0,0:20:30.01,0:20:31.09,Default,,0000,0000,0000,,saw was syntactically correct but Dialogue: 0,0:20:31.09,0:20:33.06,Default,,0000,0000,0000,,isn't going to be semantically Dialogue: 0,0:20:33.06,0:20:34.09,Default,,0000,0000,0000,,correct, which is when Dialogue: 0,0:20:34.09,0:20:36.06,Default,,0000,0000,0000,,we have the author list Dialogue: 0,0:20:36.06,0:20:39.09,Default,,0000,0000,0000,,be a mixture of objects and strings. Dialogue: 0,0:20:39.09,0:20:43.05,Default,,0000,0000,0000,,So, let's put Jeffrey Ullman here just as a string. Dialogue: 0,0:20:43.05,0:20:44.07,Default,,0000,0000,0000,,We saw that that was still Dialogue: 0,0:20:44.07,0:20:46.01,Default,,0000,0000,0000,,valid JSON, but when we Dialogue: 0,0:20:46.01,0:20:47.07,Default,,0000,0000,0000,,try to validate now, we're gonna Dialogue: 0,0:20:47.07,0:20:49.08,Default,,0000,0000,0000,,get an error because we expected Dialogue: 0,0:20:49.08,0:20:50.09,Default,,0000,0000,0000,,to see an object, we have Dialogue: 0,0:20:50.09,0:20:52.03,Default,,0000,0000,0000,,specified that the authors Dialogue: 0,0:20:52.03,0:20:54.10,Default,,0000,0000,0000,,are objects, and instead we got a string. Dialogue: 0,0:20:54.10,0:20:56.10,Default,,0000,0000,0000,,Now JSON schema does allow Dialogue: 0,0:20:56.10,0:20:58.07,Default,,0000,0000,0000,,us to specify that we Dialogue: 0,0:20:58.07,0:21:00.10,Default,,0000,0000,0000,,can have different types of data Dialogue: 0,0:21:00.10,0:21:02.06,Default,,0000,0000,0000,,in the same context, and I'm Dialogue: 0,0:21:02.06,0:21:05.02,Default,,0000,0000,0000,,going to show that with a little bit of a simpler example here. Dialogue: 0,0:21:05.02,0:21:06.06,Default,,0000,0000,0000,,So, let's first take away our Dialogue: 0,0:21:06.06,0:21:09.09,Default,,0000,0000,0000,,author there so that we're back with a valid file. Dialogue: 0,0:21:09.09,0:21:13.03,Default,,0000,0000,0000,,And what I am going to look at is simply the year values. Dialogue: 0,0:21:13.03,0:21:15.03,Default,,0000,0000,0000,,So, let suppose for whatever Dialogue: 0,0:21:15.03,0:21:16.05,Default,,0000,0000,0000,,reason that in our Dialogue: 0,0:21:16.05,0:21:17.08,Default,,0000,0000,0000,,magazines, one of the Dialogue: 0,0:21:17.08,0:21:21.02,Default,,0000,0000,0000,,years was a string and the other year was an integer. Dialogue: 0,0:21:21.02,0:21:22.04,Default,,0000,0000,0000,,So that's not gonna work out Dialogue: 0,0:21:22.04,0:21:23.06,Default,,0000,0000,0000,,right now because we have Dialogue: 0,0:21:23.06,0:21:27.01,Default,,0000,0000,0000,,specified clearly that the year must be an integer. Dialogue: 0,0:21:27.01,0:21:29.03,Default,,0000,0000,0000,,In JSON schema specifications, when we Dialogue: 0,0:21:29.03,0:21:31.04,Default,,0000,0000,0000,,want to allow multiple types Dialogue: 0,0:21:31.04,0:21:32.08,Default,,0000,0000,0000,,for values that are Dialogue: 0,0:21:32.08,0:21:34.06,Default,,0000,0000,0000,,used in the same context, we Dialogue: 0,0:21:34.06,0:21:36.06,Default,,0000,0000,0000,,actually make the type be an array. Dialogue: 0,0:21:36.06,0:21:37.08,Default,,0000,0000,0000,,So instead of just saying Dialogue: 0,0:21:37.08,0:21:38.10,Default,,0000,0000,0000,,integer, if we put Dialogue: 0,0:21:38.10,0:21:40.05,Default,,0000,0000,0000,,an array here that has Dialogue: 0,0:21:40.05,0:21:42.09,Default,,0000,0000,0000,,both integer and string that's Dialogue: 0,0:21:42.09,0:21:43.10,Default,,0000,0000,0000,,telling us that our year Dialogue: 0,0:21:43.10,0:21:45.01,Default,,0000,0000,0000,,value can be either an Dialogue: 0,0:21:45.01,0:21:46.01,Default,,0000,0000,0000,,integer or a string Dialogue: 0,0:21:46.01,0:21:48.00,Default,,0000,0000,0000,,and now when we validate, Dialogue: 0,0:21:48.00,0:21:50.02,Default,,0000,0000,0000,,we get a correct JSON file. Dialogue: 0,0:21:50.02,0:21:53.07,Default,,0000,0000,0000,,That concludes our demo of JSON schema validation. Dialogue: 0,0:21:53.07,0:21:54.09,Default,,0000,0000,0000,,Again, we've just seen Dialogue: 0,0:21:54.09,0:21:56.07,Default,,0000,0000,0000,,one example with a number Dialogue: 0,0:21:56.07,0:21:58.02,Default,,0000,0000,0000,,of the constructs that are available Dialogue: 0,0:21:58.02,0:21:59.07,Default,,0000,0000,0000,,in JSON schema, but it's not Dialogue: 0,0:21:59.07,0:22:01.02,Default,,0000,0000,0000,,nearly exhaustive, there are many Dialogue: 0,0:22:01.02,0:22:02.10,Default,,0000,0000,0000,,others, and I encourage you Dialogue: 0,0:22:02.10,0:22:04.08,Default,,0000,0000,0000,,to read a bit more about it. Dialogue: 0,0:22:04.08,0:22:06.04,Default,,0000,0000,0000,,You can download this data and Dialogue: 0,0:22:06.04,0:22:07.08,Default,,0000,0000,0000,,this schema as a starting Dialogue: 0,0:22:07.08,0:22:09.06,Default,,0000,0000,0000,,point, and start adding things playing around Dialogue: 0,0:22:09.06,0:22:10.04,Default,,0000,0000,0000,,and I think you'll get a Dialogue: 0,0:22:10.04,0:22:12.02,Default,,0000,0000,0000,,good feel for how JSON Dialogue: 0,0:22:12.02,0:22:13.04,Default,,0000,0000,0000,,schema can be used to Dialogue: 0,0:22:13.04,9:59:59.99,Default,,0000,0000,0000,,constrain the allowable data in a JSON file.