Mastering Python: Part 2: Working with JSON

Learning Python

Using Python

Mastering Python

Python is a general-purpose interpreted programming language. It emphasizes readability through the use of whitespace and supports multiple programming paradigms such as functional and object-oriented models.


Working with JSON

Used as early as 1999 in web development, the JavaScript Object Notation (JSON) has now become a language-independent notation most commonly used as part of a communication layer between programs and web services.

JSON in Python

As a modern programming language, Python also supports JSON through its json module.

JSON

Most JSON work concern two functions in Python: load() and dump().

The first, load(), takes a file object (such as returned through using open() ) and will read the entire file into memory as JSON. The second, dump(), shows the JSON data in a human-readable way.

As a Dictionary

Complex JSON data is usually loaded as a Dictionary in Python. As objects and ordered sets, the data can be accessed through its structure using either key-value pairs (Dictionary) or the position (List) of the data.

Play with the example on Repl.it!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.