JSON Basics For Beginners

json-beginners-iconWhen sending and receiving data in IOT applications and APIs you will encounter JSON formatted data.

Having a good working knowledge of JSON, and how to create and use JSON data will be very important in developing IOT applications.

In this tutorial you will learn:

  • What JSON is
  • Why it is Used
  • Basic JSON syntax
  • How to use JSON in JavaScript
  • How to use JSON in Python.

What is JSON (JavaScript Object Notation)?

JSON is a format for encoding data in human readable format for storing and sending over a network.

Although it started in JavaScript it is used in all modern programming languages.

Why is is used?

It is used because it makes it easy to store and transfer JavaScript arrays and objects as text data.

JSON Format

JSON stores data as:

  • key/value pairs
  • Data is separated using commas
  • Text data is enclosed in double quotes
  • Numerical data has no quotes.
  • Arrays are enclosed in square brackets []
  • Objects are enclosed in curly brackets {}
  • The output is a text string

Sending and Receiving JSON Data

Data like sensor in IOT apps is normally sent in JSON format. So the application program on the sensor has to package the data into a JSON string and the receiving application has to convert the JSON string into the original data format e.g. object .

All major programming languages have functions for doing this. Here we will cover JavaScript and Python.

JSON And JavaScript

There are two functions that are used for converting data from JavaScript to JSON and from JSON to JavaScript. They are:

  • JSON.stringify(JavaScript object)
  • JSON.parse(JSON string)

JavaScript JSON Examples

The examples show screen shots using the node.js command prompt for converting to and from JSON strings to JavaScript Objects.

JavaScript Array to JSON String


JavaScript Object to JSON String


JSON to JavaScript

Below shows the JSON strings b and d being converted back to JavaScript.


JSON and Python

There are two functions that are used for converting data from Python Objects to JSON and from JSON to Python Objects. They are:

  • json.dumps(Python object)
  • json.loads(JSON string)

Note: The python equivalent of a JavaScript object is a dictionary and an array is a list in Python.

Python List to JSON

Python Dictionary to JSON


JSON to Python

Below shows the JSON strings b and d being converted back to Python objects:


Where it is Used

Besides being used for transferring data between systems it is also used to configuration files especially in JavaScript and node.js applications (node-red flows).

The mongo.db database uses JSON to store documents and MYSQL has support for storing JSON objects.

I use JSON in my python and node-red data loggers.


JSON is used extensively in web and IOT applications and is a very easy methods of storing and transferring complex data as text.

Would You Be Interested In a JSON Example Workbook?

View Results

Loading ... Loading ...


JSON formatter and Validator

Related Tutorials

Please rate? And use Comments to let me know more
[Total: 1    Average: 5/5]

Leave a Reply

Your email address will not be published. Required fields are marked *