Learn JSON Basics Series
This is part one in an instructional two part series of blog posts about JSON.

JavaScript Object Notation

JSON is an easy way of parsing information as text, particularly saved as a .json file extension.

Benefits of JSON:

  • Human readable and writeable
  • Easy for machines to parse and generate
  • Use name value pairs
  • Can contain objects and arrays
  • Based on JavaScript but language agnostic (can be used with many languages)
  • Has largely replaced XML
  • WordPress API uses JSON

Example of JSON data:

[
	{
		"id": 1,
		"title": "Hello world!".
		"content": "Welcome to the world of JSON"
	},
	{
		"id": 2,
		"title": "Hello JSON!",
		"content": "Welcome to the world of JSON again"	
	}
]

The brackets ‘[]’ demonstrate that this is an array of data. The curly braces ‘{}’ are objects listed in an array. Each object is separated by a comma. Do not put a comma at the end of the last object. Within the objects are name value pairs with the key on the left and value on the right separated by a comma ‘:’. JSON requires double quotes around strings.

When writing JSON you’ll want to make sure it’s valid. Checkout jsonlint.com for help.

JSON view is all a helpful Chrome Browser Add-on that helps you view readable JSON when you view source code.

JSON Review

  • JSON is easy to read and write
  • .json extension is used for JSON files, but you can also write JSON in a JavaScript file
  • Uses objects, arrays and name value pairs to represent data
  • JSON is more strict than JavaScript, so make sure to validate

Learn More Handling JSON Objects with JavaScript ~ Part Two