154: Data: JSON JavaScript Object Notation.

Take Up Code - A podcast by Take Up Code: build your own computer games, apps, and robotics with podcasts and live classes

Categorie:

If you haven’t already, make sure to listen to the previous episode 153 about XML. Many of the concepts that I described there apply to JSON as well. JSON stands for JavaScript Object Notation and comes from the JavaScript language. But even so, it’s a good choice for representing data in any language. If you’re using JavaScript, there is a method you can call to read JSON. This method is called eval which is short for evaluate. However, I don’t recommend that you call this method because it can run code just as easy as read data. You’re better off using a library that has the ability to parse JSON data as just data. This will be the approach you’ll take with any other programming language anyway. Why should you consider using JSON? Well, you can use JSON, or XML, or any of several other techniques anytime you need to store and retrieve, or send and receive information. First of all, XML can do everything that JSON can do and then some. And JSON comes really close to being able to match XML. There are a few things that XML can do that JSON can’t such as embedding comments inside the XML, or validating that the XML adheres to a valid format. But even then, don’t be surprised if the standards change and evolve so that JSON fully matches XML. To me, it really just comes down to a choice between which formatting you like best. Usually though, JSON will be shorter just because you don’t have to worry about ending each XML tag with a duplicate ending tag. So what is JSON? I’m not going to try describing the syntax. That would involve telling you where to put commas, colons, and quotation marks. I’ll stick to the concepts. And there are two main concepts. The first is name value pairs. This is a simple concept and really just means that a value has an associated name. If we’re building an adventure game and the hero has a health of 100 and a speed of 5, then both of those values have a name. The value doesn’t have to be so simple. It could be a string, a number, true or false, have no value at all, an array, or represent an object that has it’s own name value pairs. Each of these named values is in no particular order. The second concept has to do with arrays that I just mentioned as one of the value types. An array is actually ordered, so if an item comes before another item, then that means something. At least it means something as far as JSON is concerned. Think of array values just like the first concept of named values only without the name. With an array, it’s the order that identifies values. Make sure to listen to the full episode for an example of how you might use JSON to store information about characters. Or you can also read the full transcript below. Transcript If you haven’t already, make sure to listen to the previous episode 153 about XML. Many of the concepts that I described there apply to JSON as well. JSON stands for JavaScript Object Notation and comes from the JavaScript language. But even so, it’s a good choice for representing data in any language. If you’re using JavaScript, there is a method you can call to read JSON. This method is called eval which is short for evaluate. However, I don’t recommend that you call this method because it can run code just as easy as read data. You’re better off using a library that has the ability to parse JSON data as just data. This will be the approach you’ll take with any other programming language anyway. Why should you consider using JSON? Well, you can use JSON, or XML, or any of several other techniques anytime you need to store and retrieve, or send and receive information. First of all, XML can do everything that JSON can do and then some. And JSON comes really close to being able to match XML. There are a few things that XML can do that JSON can’t such as embedding comments inside the XML, or validating that the XML adheres to a valid

Visit the podcast's native language site