JavaScript Object Notation (JSON) is a lightweight data interchange format. It is based on JavaScripts object literal notation.


Although JSON is a subset of JavaScript, it is language independent. It can be used to exchange data between programs written in all modern programming languages. It is a text format, so it is readable by both humans and machines.  It is easy to implement and easy to use.


JavaScript Object Notation (JSON) is an open standard developed by Douglas Crockford, author of , [amazon text=JavaScript : The Good Parts&asin=0596517742] , that specifies a subset of the native JavaScript object-literal syntax for use in data representation, communication, and storage.


Prior to the JSON specification, most client-server communications were being delivered in much more verbose XML snippets. JavaScript developers often work with JSON web services and frequently define internal data using JSON syntax.

A JSON object is an unordered container of name/value pairs. A name can be any string.  A value can be any JSON value, including arrays and objects. JSON objects can be nested to any depth, but generally it is most effective to keep them relatively flat. Most languages have a feature that maps easily to JSON objects, such as an object, struct, record, dictionary, hash table, property list or associative array.


The JSON array is an ordered sequence of values. A value can be any JSON value, including arrays and objects.  A value can be any JSON value, including arrays and objects. Most languages have a feature that maps easily onto JSON arrays, such as arrays, vector, list or sequence.


Although JSON is language independent, I’ll be using Node.js in my examples, however they should work within any JavaScript framework.


Creating a JSON Object

A JSON object in Node.js uses {} syntax to declare the JSON data type. In our initial example we’ll create a simple JSON object to store details about a freelancer.

We can extend this object to include a nested JSON object to include address information.

Displaying Data

After we have created our JSON object we can print the contents out to console, by simply using console.log.  This will show a native JSON object in the console.


Accessing Data

If you want to get a specific attribute of a JSON object, then you can call the attribute name directly.


If you call an unknown attribute of a JSON object, you will get an undefined value.

You can iterate through your JSON object to retrieve what attributes have been defined.


If you want to check whether a property has been defined on a JSO object you can use the hasOwnProperty function.  This is a boolean function so will return either true or false.


Editing Data

Editing JSON data can be performed by assigning new values to the object’s attribute.

You can also change a value by accessing the object like an array using the []

JSON Array

We can also combine our object to include a collection of values.

If you want to access a JSON array, for instance, using the details attribute, you can pass the index parameter to get a single JSON object.



Gary Woodfine

Freelance Full Stack Developer at
Helps businesses by improving their technical proficiencies and eliminating waste from the software development pipelines.

A unique background as business owner, marketing, software development and business development ensures that he can offer the optimum business consultancy services across a wide spectrum of business challenges.

Affiliate Disclaimer

Disclosure: Please note that some of the links included in the blog posts are affiliate links, which means I will earn a commission if you decide to make a purchase.

I only include affiliate links to products, services and companies that I have personal experience and have actually used. I only recommend them because they are helpful and useful, not because of the small commissions I make if you decide to buy something.

Please do not spend any money on these products unless you feel they are relevant, suitable and will help you achieve your goals.

Buying anyone of these products and the commisions earned will not make me an overnite multi millionaire, but they will help to cover the hosting costs and compensate for the countless hours and effort I put in to create meaningful and valuable free content I provide to help others succeed.

You've also undoubtedly noticed that I also use various advertising networks - unless of of course you're using an Ad blocker, this is also an attempt to reduce my monthly deficit I experience in providing free relevant, valuable and on occassion insightful content for the benefit of others.

I only really make some money if people click on the ads, unless of course you consider 1c per 1000 impressions real money!

Bear in mind just how many impressions I need to make before I can cover my £20 hosting costs a month!

If you are using an adblocker and guilt stricken you can of course donate using any of the buttons below, but I won't be holding my breath.

Buy me a coffeeBuy me a coffee