Demjson is a third-party module library for python, which can be used to encode and decode JSON data, including the formatting and verification functions of JSONLint .
Github address: https://github.com/dmeranda/demjson
Official address: http://deron.meranda.us/python/ demjson/
Environment configuration
Before using Demjson to encode or decode JSON data, we need to install the Demjson module first. In this tutorial we will download Demjson and install it:
$ tar -xvzf demjson-2.2.3.tar.gz $ cd demjson-2.2.3 $ python setup.py install
For more installation introduction: http://deron.meranda.us/python/demjson/install
JSON function
##encode
Python encode( ) function is used to encode Python objects into JSON strings.Syntax
demjson.encode(self, obj, nest_level=0)
Example
The following example encodes an array For JSON format data:#!/usr/bin/python import demjson data = [ { 'a' : 1, 'b' : 2, 'c' : 3, 'd' : 4, 'e' : 5 } ] json = demjson.encode(data) print json
[{"a":1,"b":2,"c":3,"d":4,"e":5}]
The above is the detailed content of How to install demjson python? Introduction to the usage of dem indicator. For more information, please follow other related articles on the PHP Chinese website!