Part 20 - Learning JSON for Beginners
Written by Eric Muss-Barnes, 2 January 2019Remember when I said you should not learn new technology, unless it is useful?
Here is some new technology called JSON.
JSON is an acronym for "JavaScript Object Notation" and is simply a type of text file, containing data for JavaScript to parse. JSON is similar (and in my opinion, inferior) to an XML file being parsed by other languages like PHP. I don't really recommend using JSON for anything, but it's very "hip" and "cool" and "trendy", so I figured I would share how it works, then you can understand why it's a bad idea to use it.
Let me give you two examples of showing data on a webpage. One will use JSON and one will use XML. These are actually a code test I did for Guitar Center when I was job hunting in the fall of 2018. The assignment was to use JSON but I decided to use both JSON and XML just to show them the advantages of the XML approach.
PART 20 - LESSON A - JSON PAGE
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec iaculis laoreet odio, sit amet rutrum ligula aliquet vitae. Phasellus venenatis rhoncus tortor at cursus. Duis et porttitor diam, sodales placerat lectus.
Name of this Instrument
Now $295.00
Name of this Instrument
Now $295.00
Name of this Instrument
Now $295.00
PART 20 - LESSON B - XML PAGE
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec iaculis laoreet odio, sit amet rutrum ligula aliquet vitae. Phasellus venenatis rhoncus tortor at cursus. Duis et porttitor diam, sodales placerat lectus.
Name of this Instrument
Now $295.00
Name of this Instrument
Now $295.00
Name of this Instrument
Now $295.00
From studying those two examples, can you spot the problems?
The XML example parses data from a file and writes actual HTML code, so when you view the sourcecode, all the data is there.
The JSON example parses data from a file and uses JavaScript to print the results in the DOM, so when you view the sourcecode, no data is there.
I know I have cited these concepts before, but it's important to understand, because JavaScript has become so trendy, and is so often utilized poorly. I'm a big fan of JavaScript. I'm not against using it. There are times when JavaScript offerers the best, simplest solution to technological problems. But using it for everything is a mistake. And you don't want to create mistaken projects of little value.
And remember, kids, the world owes you nothing... until you create things of value.
Glossary
JSON
JSON is an acronym for "JavaScript Object Notation" and is simply a type of text file containing data for JavaScript to parse. Similar to an XML file being parsed by other languages like PHP.Downloads
Other Articles