JSON in Python

What is JSON

JSON(JavaScript Object Notation) is a data-interchange format that is human-readable and used to transmit data objects consisting of attribute-value pairs. It is used primarily to transmit data between a server and web application, as an alternative to XML.

Python has a built-in module called JSON that allows you to encode and decode JSON data.

Example

In the following example, we have a Python dictionary that contains student names and grades. We will use the json.dumps() method to convert the dictionary into a JSON string.

  import json  

  # dictionary 
  d = {'Name': 'John', 'Grade': 'A', 'City': 'New York'}  

  # converting into JSON format 
  j_data = json.dumps(d)  

  print(j_data) 

Leave a Reply