How to read JSON file in Python

How to read JSON file in Python

JSON stands for JavaScript Object Notation, which is a popular data format to represent the structured data. It is an effective way to transmit the data between the server and web-applications.

The data representation in JSON is similar to the Python dictionary. The example is given below.

Example –

Read JSON file

First, we need to import the json module, and it provides the load() function to read the JSON file.

Suppose, we have a JSON file named student.json, which contains JSON objects.

Let’s understand the following example.

Output:

{"name": "Peter", "Subjects": ["English", "Political Science"]}

Explanation –

In the above code, we have used the open() function to read the JSON file. The load() function is parsed the JSON file and returned the dictionary named data.


原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/263619.html

(0)
上一篇 2022年5月30日
下一篇 2022年5月30日

相关推荐

发表回复

登录后才能评论