1 00:00:00,270 --> 00:00:01,530 This video introduces JSON. 2 00:00:02,350 --> 00:00:03,660 Let's start by talking about its pronunciation. 3 00:00:04,960 --> 00:00:07,020 Some people call it Jason, and some call it J-sahn. 4 00:00:07,970 --> 00:00:08,750 I'll do a little bit of 5 00:00:09,210 --> 00:00:10,610 investigation and discovered that the 6 00:00:10,790 --> 00:00:12,180 original developer of JSON calls 7 00:00:12,620 --> 00:00:14,020 it JSON so, I'll do that too. 8 00:00:15,140 --> 00:00:18,200 Like XML, JSON can be thought of as a data model. 9 00:00:18,890 --> 00:00:20,250 An alternative to the relational data 10 00:00:20,510 --> 00:00:21,690 model that is more 11 00:00:21,980 --> 00:00:23,660 appropriate for semi-structured data. 12 00:00:24,840 --> 00:00:26,320 In this video I'll introduce the 13 00:00:26,410 --> 00:00:27,650 basics of JSON and I'll 14 00:00:27,960 --> 00:00:28,930 actually compare JSON to the 15 00:00:29,220 --> 00:00:31,930 relational data model and I'll compare it to XML. 16 00:00:32,590 --> 00:00:33,870 But it's not crucial to have 17 00:00:34,070 --> 00:00:36,180 watched those videos to get something out of this one. 18 00:00:37,150 --> 00:00:38,130 Now among the three models 19 00:00:38,600 --> 00:00:39,900 - the relational model, XML, and 20 00:00:40,000 --> 00:00:41,630 JSON - JSON is by 21 00:00:41,800 --> 00:00:42,890 a large margin the newest, 22 00:00:43,460 --> 00:00:44,330 and it does show there aren't 23 00:00:44,720 --> 00:00:45,770 as many tools for JSON 24 00:00:46,570 --> 00:00:48,580 as we have for XML and 25 00:00:48,710 --> 00:00:50,110 certainly not as we have for relational. 26 00:00:51,600 --> 00:00:53,840 JSON stands for Javascript object notation. 27 00:00:54,690 --> 00:00:56,040 Although it's evolved to become pretty 28 00:00:56,200 --> 00:00:58,650 much independent of Javascript at this point. 29 00:00:59,620 --> 00:01:02,430 The little snippet of Jason in the corner right now mostly for decoration. 30 00:01:03,060 --> 00:01:04,940 We'll talk about the details in just a minute. 31 00:01:05,770 --> 00:01:07,260 Now JSON was designed 32 00:01:07,580 --> 00:01:09,270 originally for what's called 33 00:01:09,680 --> 00:01:10,950 serializing data objects. 34 00:01:11,330 --> 00:01:13,090 That is taking the objects that 35 00:01:13,210 --> 00:01:14,460 are in a program and sort 36 00:01:14,550 --> 00:01:15,460 of writing them down in a 37 00:01:15,670 --> 00:01:17,630 serial fashion, typically in files. 38 00:01:18,770 --> 00:01:19,730 one thing about json 39 00:01:19,970 --> 00:01:21,170 is that it is human readable, 40 00:01:21,860 --> 00:01:23,000 similar to the way xml 41 00:01:23,230 --> 00:01:24,760 is human readable and is 42 00:01:25,250 --> 00:01:26,570 often use for data interchange. 43 00:01:27,400 --> 00:01:28,810 So, for writing out, say 44 00:01:28,930 --> 00:01:30,220 the objects program so that 45 00:01:30,310 --> 00:01:31,760 they can be exchanged with another 46 00:01:32,090 --> 00:01:33,310 program and read into that one. 47 00:01:34,290 --> 00:01:35,840 Also, just more generally, because 48 00:01:36,500 --> 00:01:37,630 json is not as rigid 49 00:01:38,120 --> 00:01:39,760 as the relational model, it's generally 50 00:01:40,300 --> 00:01:42,050 useful for representing and for 51 00:01:42,150 --> 00:01:43,220 storing data that doesn't 52 00:01:43,490 --> 00:01:46,450 have rigid structure that we've been calling semi-structured data. 53 00:01:47,530 --> 00:01:48,740 As I mentioned json is 54 00:01:49,090 --> 00:01:51,090 no longer closely tied to 55 00:01:51,440 --> 00:01:53,610 Many different programming languages do 56 00:01:54,020 --> 00:01:55,820 have parsers for reading json 57 00:01:56,000 --> 00:01:57,430 data into the program and 58 00:01:57,560 --> 00:01:58,980 for writing out json data as well. 59 00:02:00,110 --> 00:02:01,110 Now, let's talk about the basic 60 00:02:01,640 --> 00:02:03,200 constructs in JSON, and as 61 00:02:03,350 --> 00:02:05,470 we will see this constructs are recursively defined. 62 00:02:06,520 --> 00:02:07,740 We'll use the example JSON 63 00:02:08,240 --> 00:02:09,000 data shown on the screen 64 00:02:09,670 --> 00:02:10,990 and that data is also available 65 00:02:11,520 --> 00:02:13,090 in a file for download from the website. 66 00:02:14,350 --> 00:02:17,630 The basic atomic values in JSON are fairly typical. 67 00:02:18,290 --> 00:02:20,240 We have numbers, we have strings. 68 00:02:21,630 --> 00:02:23,250 We also have Boolean Values 69 00:02:23,670 --> 00:02:24,310 although there are none of those 70 00:02:24,570 --> 00:02:27,540 in this example, that's true and false, and no values. 71 00:02:29,190 --> 00:02:30,270 There are two types of composite 72 00:02:30,610 --> 00:02:33,120 values in JSON: objects and arrays. 73 00:02:34,490 --> 00:02:35,590 Objects are enclosed in curly 74 00:02:36,150 --> 00:02:37,470 braces and they consist 75 00:02:37,660 --> 00:02:39,440 of sets of label-value pairs. 76 00:02:40,290 --> 00:02:41,370 For example, we have an 77 00:02:41,690 --> 00:02:44,270 object here that has a first name and a last name. 78 00:02:44,870 --> 00:02:46,530 We have a more - 79 00:02:46,760 --> 00:02:48,050 bigger, let's say, object here 80 00:02:48,630 --> 00:02:51,100 that has ISBN, price, edition, and so on. 81 00:02:51,760 --> 00:02:52,930 When we do our JSON demo, 82 00:02:53,280 --> 00:02:54,950 we'll go into these constructs in more detail. 83 00:02:55,430 --> 00:02:56,720 At this point, we're just introducing them. 84 00:02:57,670 --> 00:02:59,130 the second type of composite 85 00:02:59,460 --> 00:03:00,840 value in JSON is arrays, 86 00:03:01,160 --> 00:03:02,600 and arrays are enclosed in square 87 00:03:03,040 --> 00:03:05,260 brackets with commas between the array elements. 88 00:03:06,000 --> 00:03:07,000 Actually we have commas in the objects 89 00:03:07,390 --> 00:03:09,640 as and arrays are list of values. 90 00:03:10,530 --> 00:03:11,680 For example, we can see 91 00:03:11,890 --> 00:03:13,330 here that authors is a 92 00:03:13,620 --> 00:03:15,000 list of author objects. 93 00:03:16,310 --> 00:03:17,630 Now I mentioned that the constructs 94 00:03:18,200 --> 00:03:19,830 are recursive, specifically the values 95 00:03:20,490 --> 00:03:21,800 inside arrays can be anything, 96 00:03:22,180 --> 00:03:23,740 they can be other arrays or objects, 97 00:03:23,910 --> 00:03:25,250 space values and the values 98 00:03:26,180 --> 00:03:27,340 are making up the label value 99 00:03:27,660 --> 00:03:28,980 pairs and objects can also 100 00:03:29,400 --> 00:03:31,990 be any composite value or a base value. 101 00:03:32,320 --> 00:03:33,450 And I did want to 102 00:03:33,660 --> 00:03:34,720 mention, by the way, that sometime 103 00:03:34,920 --> 00:03:35,970 this word label here for 104 00:03:36,120 --> 00:03:38,680 label value pairs is called a "property". 105 00:03:39,770 --> 00:03:40,840 So, just like XML, JSON 106 00:03:41,520 --> 00:03:43,920 has some basic structural requirements in 107 00:03:44,010 --> 00:03:44,980 its format but it doesn't 108 00:03:45,350 --> 00:03:47,090 have a lot of requirements in terms of uniformity. 109 00:03:47,810 --> 00:03:49,160 We have a couple of examples 110 00:03:49,720 --> 00:03:51,360 of heterogeneity in here, for 111 00:03:51,530 --> 00:03:52,610 example, this book has an 112 00:03:52,690 --> 00:03:53,640 edition and the other one 113 00:03:53,840 --> 00:03:56,650 doesn't this book has a remark and the other one doesn't. 114 00:03:57,710 --> 00:03:58,900 But we'll see many more examples 115 00:03:59,360 --> 00:04:00,650 of heterogeneity when we do 116 00:04:00,790 --> 00:04:02,560 the demo and look into JSON data in more detail. 117 00:04:03,880 --> 00:04:05,670 Now let's compare JSON and the relational model. 118 00:04:06,430 --> 00:04:07,400 We will see that many of 119 00:04:07,470 --> 00:04:08,960 the comparisons are fairly similar 120 00:04:09,290 --> 00:04:11,270 to when we compared XML to the relational model. 121 00:04:12,670 --> 00:04:15,270 Let's start with the basic structures underling the data model. 122 00:04:15,940 --> 00:04:18,420 So, the relational model is based on tables. 123 00:04:18,810 --> 00:04:20,500 We set up structure of 124 00:04:20,700 --> 00:04:21,830 table, a set of columns, and 125 00:04:22,070 --> 00:04:24,270 then the data becomes rows in those tables. 126 00:04:25,300 --> 00:04:27,010 JSON is based instead on 127 00:04:27,440 --> 00:04:28,870 sets, the sets of label 128 00:04:29,460 --> 00:04:32,560 pairs and arrays and as we saw, they can be nested. 129 00:04:34,090 --> 00:04:35,440 One of the big differences between 130 00:04:35,640 --> 00:04:37,380 the two models, of course, is the scheme. 131 00:04:38,400 --> 00:04:39,710 So the Relational model has a 132 00:04:39,830 --> 00:04:41,000 Schema fixed in advance, 133 00:04:41,740 --> 00:04:42,910 you set it up before you 134 00:04:43,010 --> 00:04:44,550 have any data loaded and then 135 00:04:44,800 --> 00:04:46,570 all data needs to confirm to that Schema. 136 00:04:47,520 --> 00:04:48,330 Jason on the other other 137 00:04:48,500 --> 00:04:51,310 hand typically does not require a schema in advance. 138 00:04:52,110 --> 00:04:53,410 In fact, the schema and the 139 00:04:53,620 --> 00:04:54,870 data are kinda mix together 140 00:04:55,330 --> 00:04:56,560 just like an xml, and 141 00:04:56,650 --> 00:04:57,750 this is often referred to as 142 00:04:58,540 --> 00:05:00,550 self-describing data, where the 143 00:05:00,680 --> 00:05:03,200 schema elements are within the data itself. 144 00:05:04,370 --> 00:05:05,480 And this is of course typically 145 00:05:05,920 --> 00:05:08,060 more flexible than the to a model. 146 00:05:08,210 --> 00:05:10,430 But there are advantages to having schema [sp?] 147 00:05:10,600 --> 00:05:10,950 as well, definitely. 148 00:05:12,310 --> 00:05:13,490 As far as queries go, one 149 00:05:13,760 --> 00:05:15,080 of the nice features of the 150 00:05:15,160 --> 00:05:16,440 relational model is that there 151 00:05:16,630 --> 00:05:20,100 are simple, expressive languages for clearing the database. 152 00:05:21,960 --> 00:05:23,800 In terms of json, although a 153 00:05:23,920 --> 00:05:24,910 few New things have been proposed; 154 00:05:25,960 --> 00:05:27,380 at this point there's nothing widely 155 00:05:27,950 --> 00:05:29,280 used for querying Jason data. 156 00:05:29,580 --> 00:05:30,840 Typically Jason data is 157 00:05:31,010 --> 00:05:33,170 read into a program and it's manipulated programatically. 158 00:05:34,550 --> 00:05:35,690 Now let me interject that this 159 00:05:35,860 --> 00:05:37,890 video is being made in February 2012. 160 00:05:38,690 --> 00:05:40,240 So it is possible 161 00:05:40,640 --> 00:05:41,930 that some json query languages 162 00:05:42,370 --> 00:05:43,630 will emerge and become 163 00:05:44,050 --> 00:05:44,990 widely used there is just 164 00:05:45,080 --> 00:05:46,490 nothing used at this point. 165 00:05:46,810 --> 00:05:47,560 There are some proposals. 166 00:05:47,930 --> 00:05:49,110 There's a JSON path language, 167 00:05:49,940 --> 00:05:51,540 JSON Query, a language called jaql. 168 00:05:52,370 --> 00:05:53,410 It may be that just like 169 00:05:53,560 --> 00:05:54,830 XML, the query language are 170 00:05:55,010 --> 00:05:56,700 gonna follow the prevalent use 171 00:05:57,140 --> 00:05:58,550 of the data format or the data model. 172 00:05:59,130 --> 00:06:01,390 But that does not happened yet, as of February 2012. 173 00:06:01,570 --> 00:06:03,380 How about ordering? 174 00:06:04,020 --> 00:06:06,700 One aspect of the relational model is that it's an unordered model. 175 00:06:07,030 --> 00:06:08,570 It's based on sets and 176 00:06:08,690 --> 00:06:09,620 if we want to see relational 177 00:06:10,230 --> 00:06:13,150 data in sorted order then we put that inside a query. 178 00:06:14,150 --> 00:06:15,890 In JSON, we have arrays as 179 00:06:16,030 --> 00:06:18,480 one of the basic data structures, and arrays are ordered. 180 00:06:19,280 --> 00:06:20,400 Of course, there's also the fact like 181 00:06:20,880 --> 00:06:22,070 XML that JSON data is 182 00:06:22,250 --> 00:06:23,830 often is usually written files 183 00:06:24,440 --> 00:06:26,020 and files themselves are naturally ordered, 184 00:06:26,710 --> 00:06:27,560 but the ordering of the data 185 00:06:27,680 --> 00:06:29,910 in files usually isn't relevant, 186 00:06:30,430 --> 00:06:31,530 sometimes it is, but 187 00:06:31,820 --> 00:06:33,510 typically not finally in 188 00:06:33,620 --> 00:06:35,180 terms of implementation, for the 189 00:06:35,300 --> 00:06:36,890 relational model, there are 190 00:06:37,160 --> 00:06:39,410 systems that implement the relational model natively. 191 00:06:39,910 --> 00:06:42,120 They're very generally quite 192 00:06:42,740 --> 00:06:43,630 efficient and powerful systems. 193 00:06:44,580 --> 00:06:45,870 For json, we haven't yet 194 00:06:46,270 --> 00:06:47,700 seen stand alone database systems 195 00:06:48,090 --> 00:06:49,500 that use json their data 196 00:06:49,780 --> 00:06:51,200 model instead JSON is 197 00:06:51,360 --> 00:06:53,390 more typically coupled with programming languages. 198 00:06:54,580 --> 00:06:55,730 One thing I should add however 199 00:06:56,690 --> 00:06:59,730 JSON is used in NoSQL systems. 200 00:07:00,760 --> 00:07:02,130 We do have videos about NoSQL 201 00:07:02,610 --> 00:07:04,730 systems you may or may not have, have watched those yet. 202 00:07:05,290 --> 00:07:07,930 There's a couple of different ways that JSON is used used in those systems. 203 00:07:08,650 --> 00:07:10,120 One of them is just as 204 00:07:10,240 --> 00:07:11,620 a format for reading data 205 00:07:11,870 --> 00:07:13,990 into the systems and writing data out from the systems. 206 00:07:14,820 --> 00:07:15,570 The other way that it is 207 00:07:15,630 --> 00:07:16,950 used is that some of the 208 00:07:17,020 --> 00:07:17,950 note systems are what are 209 00:07:18,070 --> 00:07:20,100 called "Document Management Systems" where 210 00:07:20,220 --> 00:07:21,930 the documents themselves may contain 211 00:07:22,410 --> 00:07:23,750 JSON data and then the systems 212 00:07:24,170 --> 00:07:25,440 will have special features for manipulating 213 00:07:26,230 --> 00:07:28,610 the JSON in the document is better stored by the system. 214 00:07:29,560 --> 00:07:31,330 Now let's compared json and XML. 215 00:07:32,070 --> 00:07:34,960 This is actually a hotly debated comparison right now. 216 00:07:35,310 --> 00:07:37,510 There are signification overlap in 217 00:07:37,830 --> 00:07:40,160 the usage of JSON and XML. 218 00:07:40,230 --> 00:07:41,290 Both of them are very 219 00:07:41,600 --> 00:07:43,460 good for putting semi-structured data 220 00:07:43,990 --> 00:07:45,360 into a file format 221 00:07:46,190 --> 00:07:47,140 and using it for data interchange. 222 00:07:48,270 --> 00:07:49,370 And so because there's so 223 00:07:49,510 --> 00:07:50,620 much overlap in what they're used 224 00:07:50,970 --> 00:07:53,300 for, it's not surprising that there's significant debate. 225 00:07:54,200 --> 00:07:54,970 I'm not gonna take sides. 226 00:07:55,400 --> 00:07:56,430 I'm just going to try to give you a comparison. 227 00:07:57,690 --> 00:07:58,710 Let's start by looking at the 228 00:07:58,800 --> 00:08:01,740 verbosity of expressing data in the two languages. 229 00:08:02,650 --> 00:08:03,640 So it is the case 230 00:08:03,980 --> 00:08:05,140 that XML is in general, 231 00:08:05,750 --> 00:08:07,810 a little more verbose than Jason. 232 00:08:08,330 --> 00:08:09,910 So the same data expressed in 233 00:08:09,990 --> 00:08:11,110 the 2 formats will tend to 234 00:08:11,180 --> 00:08:12,470 have more characters [xx] than Json 235 00:08:12,630 --> 00:08:14,070 and you can see that 236 00:08:14,260 --> 00:08:16,170 in our examples because our big 237 00:08:16,530 --> 00:08:17,800 Json example was actually pretty 238 00:08:18,070 --> 00:08:20,280 much the same data that we used when we showed XML. 239 00:08:20,540 --> 00:08:22,140 And the reason for 240 00:08:22,280 --> 00:08:23,060 XML being a bit more 241 00:08:23,260 --> 00:08:24,860 verbose largely has to 242 00:08:24,950 --> 00:08:26,440 do actually with closing tags, 243 00:08:26,940 --> 00:08:28,430 and some other features. 244 00:08:29,220 --> 00:08:30,260 But I'll let you judge 245 00:08:30,570 --> 00:08:31,990 for yourself whether the somewhat 246 00:08:32,580 --> 00:08:34,650 longer expression of XML is a problem. 247 00:08:35,640 --> 00:08:37,350 Second is complexity, and here, 248 00:08:37,610 --> 00:08:38,940 too, most people would say 249 00:08:39,290 --> 00:08:41,990 that XML is a bit more complex than JSON. 250 00:08:42,360 --> 00:08:45,060 I'm not sure I entirely agree with that comparison. 251 00:08:45,980 --> 00:08:47,210 If you look at the subset 252 00:08:47,690 --> 00:08:48,920 of XML that people really 253 00:08:49,210 --> 00:08:50,690 use, you've got attributes, 254 00:08:51,190 --> 00:08:52,420 sub elements and text, and 255 00:08:52,520 --> 00:08:53,960 that's more or less it. 256 00:08:54,080 --> 00:08:55,070 If you look at Json, you got 257 00:08:55,290 --> 00:08:57,710 your basic values and you've got your objects and your arrays. 258 00:08:58,380 --> 00:08:59,210 I think the issue is that 259 00:08:59,430 --> 00:09:01,010 XML has a lot of 260 00:09:01,360 --> 00:09:03,220 extra stuff that goes along with it. 261 00:09:03,380 --> 00:09:05,400 So if you read the entire XML specification. 262 00:09:06,100 --> 00:09:07,850 It will take you a long time. 263 00:09:08,120 --> 00:09:09,750 JSON, you can grasp the 264 00:09:10,030 --> 00:09:11,670 entire specification a little bit more quickly. 265 00:09:12,680 --> 00:09:13,360 Now let's turn to validity. 266 00:09:14,340 --> 00:09:15,900 And by validity, I mean the 267 00:09:16,180 --> 00:09:18,510 ability to specify constraints or 268 00:09:18,630 --> 00:09:20,090 restriction or schema on 269 00:09:20,670 --> 00:09:22,160 the structure of data 270 00:09:22,680 --> 00:09:24,060 in one of these models, and 271 00:09:24,200 --> 00:09:26,100 have it enforced by tools or by a system. 272 00:09:27,070 --> 00:09:28,480 Specifically in XML we 273 00:09:28,630 --> 00:09:30,080 have the notion of document type 274 00:09:30,290 --> 00:09:32,110 descriptors, or DTDs, we also 275 00:09:32,450 --> 00:09:34,360 have XML Schema which 276 00:09:34,620 --> 00:09:37,080 gives us XSD's, XML Schema Descriptors. 277 00:09:38,250 --> 00:09:39,480 And these are schema like 278 00:09:39,820 --> 00:09:41,540 things that we can specify, and 279 00:09:41,650 --> 00:09:42,800 we can have our data checked to 280 00:09:42,890 --> 00:09:43,800 make sure it conforms to the 281 00:09:43,900 --> 00:09:45,640 schema, and these are, I would say, 282 00:09:45,990 --> 00:09:48,240 fairly widely used at this point for XML. 283 00:09:49,180 --> 00:09:50,970 For JSON, there's something called JSON Schema. 284 00:09:51,390 --> 00:09:53,760 And, you know, similar to 285 00:09:53,970 --> 00:09:55,150 XML Schema, it's a way 286 00:09:55,450 --> 00:09:57,010 to specify the structure and then 287 00:09:57,080 --> 00:09:58,410 we can check that JSON conforms 288 00:09:58,920 --> 00:10:01,570 that and we will see some of that in our demo. 289 00:10:02,570 --> 00:10:04,380 The current status, February 290 00:10:04,880 --> 00:10:06,310 2012 is that this is 291 00:10:07,140 --> 00:10:08,960 not widely used this point. 292 00:10:09,150 --> 00:10:11,000 But again, it could really just be evolution. 293 00:10:11,540 --> 00:10:13,710 If we look back 294 00:10:14,180 --> 00:10:14,920 at XML, as it was originally 295 00:10:15,740 --> 00:10:17,450 proposed, probably we didn't 296 00:10:17,760 --> 00:10:18,520 see a whole of lot of use 297 00:10:18,770 --> 00:10:19,910 of DTDs, and in fact not 298 00:10:20,700 --> 00:10:22,540 as XSDs for sure until later on. 299 00:10:22,760 --> 00:10:25,630 So we'll just have to see whether JSON evolves in a similar way. 300 00:10:26,800 --> 00:10:29,970 Now the programming interface is where JSON really shines. 301 00:10:31,110 --> 00:10:34,030 The programming interface for XML can be fairly clunky. 302 00:10:34,960 --> 00:10:37,130 The XML model, the attributes 303 00:10:37,540 --> 00:10:38,640 and sub-elements and so on, 304 00:10:39,070 --> 00:10:40,650 don't typically match the model 305 00:10:41,240 --> 00:10:43,500 of data inside a programming language. 306 00:10:43,830 --> 00:10:45,900 In fact, that's something called the impedance mismatch. 307 00:10:47,200 --> 00:10:48,440 The impedance miss match 308 00:10:48,720 --> 00:10:49,970 has been discussed in database 309 00:10:50,500 --> 00:10:52,250 systems actually, for decades 310 00:10:52,840 --> 00:10:54,100 because one of the original 311 00:10:54,580 --> 00:10:56,000 criticisms of relational database 312 00:10:56,450 --> 00:10:57,480 systems is that the data 313 00:10:57,760 --> 00:10:59,120 structures used in the database, 314 00:10:59,720 --> 00:11:01,340 specifically tables, didn't match 315 00:11:01,710 --> 00:11:04,050 directly with the data structures and programming languages. 316 00:11:04,420 --> 00:11:05,300 So there had to be some manipulation 317 00:11:05,310 --> 00:11:07,990 at the interface between programming languages and the database system and that's the mismatch. 318 00:11:09,140 --> 00:11:11,250 So that same impedance mismatch 319 00:11:13,050 --> 00:11:14,750 is pretty much present 320 00:11:15,150 --> 00:11:17,540 in XML wherein JSON is 321 00:11:17,790 --> 00:11:19,050 really a more direct mapping 322 00:11:19,830 --> 00:11:22,930 between many programming languages and the structures of JSON. 323 00:11:23,990 --> 00:11:25,060 Finally, let's talk about querying. 324 00:11:25,880 --> 00:11:26,950 I've already touched on this 325 00:11:27,120 --> 00:11:28,470 a bit, but JSON does not 326 00:11:28,800 --> 00:11:30,740 have any mature, widely 327 00:11:31,230 --> 00:11:32,640 used query languages at this point. 328 00:11:33,420 --> 00:11:34,390 for XML we do have 329 00:11:34,580 --> 00:11:36,490 XPath, we have XQuery, 330 00:11:36,900 --> 00:11:38,770 we have XSLT. 331 00:11:39,410 --> 00:11:40,990 Maybe not all of 332 00:11:41,080 --> 00:11:42,700 them are widely used but there's 333 00:11:42,910 --> 00:11:44,280 no question that XPath at least and 334 00:11:44,400 --> 00:11:46,000 XSL are used quiet a bit. 335 00:11:46,930 --> 00:11:48,140 As far as Json goes there 336 00:11:48,450 --> 00:11:50,190 is a proposal called Json path. 337 00:11:50,660 --> 00:11:52,030 It looks actually quiet a lot 338 00:11:52,180 --> 00:11:54,400 like XPath maybe he'll catch on. 339 00:11:55,030 --> 00:11:56,360 There's something called JSON Query. 340 00:11:56,760 --> 00:11:58,110 Doesn't look so much like 341 00:11:58,570 --> 00:12:00,660 XML Query, I mean, XQuery. 342 00:12:01,680 --> 00:12:02,670 and finally, there has been a 343 00:12:02,950 --> 00:12:06,090 proposal called [xx] language, but 344 00:12:07,070 --> 00:12:08,440 again as of February 2012 345 00:12:08,730 --> 00:12:09,630 all of these are still very 346 00:12:10,110 --> 00:12:12,360 early, so we just don't know what's going to catch on. 347 00:12:13,160 --> 00:12:15,260 So now let's talk about the validity of JSON data. 348 00:12:16,290 --> 00:12:17,410 So do JSON data that's 349 00:12:17,730 --> 00:12:19,610 syntacti[xx] valid, simply needs 350 00:12:19,710 --> 00:12:21,570 to adhere to the basic structural requirements. 351 00:12:22,550 --> 00:12:23,890 As a reminder, that would be 352 00:12:24,110 --> 00:12:25,240 that we have sets of label 353 00:12:25,610 --> 00:12:26,940 value pairs, we have arrays 354 00:12:27,350 --> 00:12:28,660 of values and our values 355 00:12:29,330 --> 00:12:30,350 are from predefined types. 356 00:12:31,180 --> 00:12:33,430 And again, these values here are defined recursively. 357 00:12:34,600 --> 00:12:35,680 So we start with a JSON 358 00:12:35,810 --> 00:12:36,980 file and we send 359 00:12:37,190 --> 00:12:38,590 it to a the parser 360 00:12:39,010 --> 00:12:40,140 may determine that the file 361 00:12:40,510 --> 00:12:42,230 has syntactic errors or if 362 00:12:42,380 --> 00:12:44,170 the file is syntactically correct then 363 00:12:44,450 --> 00:12:46,620 it can parsed into objects in a programming language. 364 00:12:47,740 --> 00:12:48,950 Now if we're interested in semantically 365 00:12:49,760 --> 00:12:51,290 valid JSON; that is 366 00:12:51,500 --> 00:12:52,530 JSON that conforms to 367 00:12:52,640 --> 00:12:53,840 some constraints or a schema, 368 00:12:54,450 --> 00:12:55,600 then in addition to checking the 369 00:12:55,670 --> 00:12:57,650 basics structural requirements, we check 370 00:12:57,880 --> 00:12:59,970 whether JSON conforms to the specified schema. 371 00:13:00,840 --> 00:13:02,040 If we use a language like JSON 372 00:13:02,340 --> 00:13:03,560 schema for example, we put 373 00:13:03,840 --> 00:13:05,420 a specification in as a 374 00:13:05,790 --> 00:13:07,820 separate file, and in 375 00:13:07,960 --> 00:13:09,390 fact JSON schema is expressed in 376 00:13:09,580 --> 00:13:10,880 JSON itself, as we'll see 377 00:13:11,020 --> 00:13:12,510 in our demo, we send it 378 00:13:12,630 --> 00:13:13,730 to a validator and that 379 00:13:13,870 --> 00:13:15,090 validator might find that there 380 00:13:15,990 --> 00:13:16,830 are some syntactic errors or 381 00:13:16,900 --> 00:13:17,640 it may find that there are 382 00:13:17,750 --> 00:13:19,180 some symantic errors so the 383 00:13:19,310 --> 00:13:20,460 data could to be correct syntactically 384 00:13:21,490 --> 00:13:22,440 but not conform to the schema. 385 00:13:23,550 --> 00:13:25,160 If it's both syntactically and semantically 386 00:13:25,740 --> 00:13:26,540 correct then it can move 387 00:13:26,800 --> 00:13:27,980 on to the parser where 388 00:13:28,170 --> 00:13:29,640 will be parsed again into 389 00:13:30,090 --> 00:13:31,260 objects in a programming language. 390 00:13:32,350 --> 00:13:35,190 So to summarize, JSON stands for Java Script Object Notation. 391 00:13:36,220 --> 00:13:37,670 It's a standard for taking data 392 00:13:38,060 --> 00:13:41,220 objects and serializing them into a format that's human readable. 393 00:13:41,580 --> 00:13:43,010 It's also very useful for 394 00:13:43,290 --> 00:13:44,980 exchanging data between programs, 395 00:13:46,010 --> 00:13:47,300 and for representing and storing 396 00:13:48,120 --> 00:13:49,990 semi-structured data in a flexible fashion. 397 00:13:51,220 --> 00:13:52,560 In the next video we'll go 398 00:13:52,770 --> 00:13:54,360 live with a demonstration of JSON. 399 00:13:55,020 --> 00:13:55,690 We'll use a couple of JSON 400 00:13:56,260 --> 00:13:57,470 editors, we'll take a 401 00:13:57,600 --> 00:13:59,100 look at the structure of JSON 402 00:13:59,450 --> 00:14:00,920 data, when it's syntactically correct. 403 00:14:01,800 --> 00:14:03,120 We'll demonstrate how it's very 404 00:14:03,540 --> 00:14:04,800 flexible when our data might 405 00:14:05,050 --> 00:14:06,310 irregular, and we'll also 406 00:14:06,850 --> 00:14:09,170 demonstrate schema checking using 407 00:14:09,470 --> 00:14:10,710 an example of JSON's schema.