beanz Magazine

JSON

eliazar on Flickr

JSON, or JavaScript Object Notation, is an elegant way to organize data into key:value pairs and make web applications work like software.

In 2001, programmers who wanted to keep a constant connection open between a web browser and a web server had few choices. Flash or Java applets were common solutions. A constant connection is critical for web applications that work like software downloaded to your computer. Among other problems, web browsers shut down connections to remote servers every so often.

One solution to this connectivity problem is JSON. It recycles the connections between a web browser and remote server while providing a simple way to organize and transmit data.

JSON, or JavaScript Object Notation, may have started as part of the JavaScript language but it has become useful to any programming language where pairs of data are needed. It is language independent. JSON is used primarily to transfer data between web servers and web applications, as an alternative to XML with its more structured format.

With JSON, for example, data is organized into keys and their values. While keys need to be unique, values can be anything. The key in your pair can be a unique ID and the value a collection of data. In XML, another way to structure data, your collection of data would be broken down into a more structured set of tags. It is possible to have your collection of data be in XML format, but it’s not required. Your collection of data, for example, could be a binary file like an image. Or it could be co-ordinates for a map.

The JSON specification has data types and syntax. Data types include numbers, strings, booleans, objects, arrays, and null. These are the same or similar to any programming language. The JSON syntax is fairly simple: data is organized into pairs with commas (,) and braces {} used to mark off parts of a data file.

{
    "firstName": "John",
    "lastName": "Smith",
    "age": 25,
    "address": {
        "streetAddress": "21 2nd Street",
        "city": "New York",
        "state": "NY",
        "postalCode": 10021
    },
    "phoneNumbers": [
        {
            "type": "home",
            "number": "212 555-1234"
        },
        {
            "type": "fax",
            "number": "646 555-4567"
        }
    ]
}

Notice a few things with this example from Wikipedia:

  • The first and last {} braces contain the full JSON record.
  • key:value pairs are separated by a single colon (:).
  • key:value pairs are defined by “” double quotes before and after the key or value.
  • key:value pairs are separated from each other by a comma (,).
  • Some values, for example, for the key address, can include their own set of key:value pairs marked off by {} braces.
  • Some values, for example, for the key phoneNumbers, can include multiple sets of key:value pairs which are marked off by [] braces.

Data in JSON format is parsed by software applications, including Firefox, Internet Explorer, and other web browsers.

And if you want to learn a big word today, key:value pairs are also called associative arrays because keys are associated with their values in pairs.

Douglas Crockford is credited with realizing part of the JavaScript language could be adapted to solve the problem of maintaining connections between web browsers and remote servers, as well as provide a simple structure to organize data. Aside from Flash and Java applets, in 2001 other techniques included using web frames (remember those?) to silently refresh data in the web browser. JSON is a far more silent and elegant solution, with less impact on a web browser than Flash, Java applets, or frames.

If you use GMail or any web mail, then you know how JSON allows web browsers to act like Apple Mail or Microsoft Outlook, two software applications downloaded to computers to download, manage, and send email.

Learn More

JSON

http://www.json.org/
http://en.wikipedia.org/wiki/JSON
http://www.w3schools.com/json/
http://msdn.microsoft.com/en-us/library/bb299886.aspx
http://www.techterms.com/definition/json
http://www.copterlabs.com/blog/json-what-it-is-how-it-works-how-to-use-it/

Douglas Crockford

http://en.wikipedia.org/wiki/Douglas_Crockford
http://crockford.com/

Also In The March 2014 Issue

An Interview with Ben Heck

Ben Heckendorn is a self-taught maker with high energy, an internet show on Element14 (The Ben Heck Show), and a wonderfully wicked sense of humor. He also inspired this issue of the magazine.

Circuit Diagrams

Circuit diagrams are maps used to design and build electronic devices. This article describes connections, components, history, and tools used to create circuit diagrams.

Electronics Projects for Beginners

Here are links to projects, tutorials, parts, and online communities to help you get started with electronics projects for beginners.

Zina Lahr

Meet someone who used her love of electronics to create deeply fun and personal robots, gadgets, and other cool stuff.

Version Control Software

Version control software captures an evolving snapshot of one set of code along with all changes in case older versions need to be retrieved.

Brackets, Semicolons, or Nothing, Oh My

How do programming languages know what to process? And in the correct order?

JSON

JSON, or JavaScript Object Notation, is an elegant way to organize data into key:value pairs and make web applications work like software.

I do not think there is any thrill that can go through the human heart like that felt by the inventor as he sees some creation of the brain unfolding to success.

How to Use an Electronic Breadboard

Electronic breadboards are used to prototype electronic circuit designs and projects without messy solder or hot soldering irons.

Learn More Links for March 2014

Links from the bottom of all the March 2014 articles, collected in one place for you to print, share, or bookmark.

Node.js

Node.js is a software platform to create fast, scalable web applications quickly. These applications also use JavaScript on the server and web browsers.

Non-Relational Databases

These databases are relatively new technology to store data in databases. Here are a few options to explore.

News Wire Stories for March 2014

Interesting stories about computer science, software programming, and technology for the month of February 2014.