JSON with Python

The demjson package is a comprehensive Python language library to read and write JSON, the popular language-independent data format standard.It includes a command tool, jsonlint, that allows you to easily check and validate any JSON document, and spot any potential data portability issues. It can also reformat and re-indent a JSON document to make it easier to read.

 

Installing demjson:

Download and install the package to start encoding and decoding JSON in python with the following commands,

$tar xvfz demjson-1.6.tar.gz
$cd demjson-1.6
$python setup.py install

 

Eg:

 >>> import demjson

>>> demjson.encode( [‘one’,42,True,None] )   # From Python to JSON

‘[“one”,42,true,null]’

>>> demjson.decode( ‘[“one”,42,true,null]’ ) # From JSON to Python

[‘one’, 42, True, None]

Advertisements

One thought on “JSON with Python

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s