Home >Backend Development >Python Tutorial >How to install demjson python? Introduction to the usage of dem indicator

How to install demjson python? Introduction to the usage of dem indicator

Tomorin
TomorinOriginal
2018-08-17 14:45:214412browse

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

How to install demjson python? Introduction to the usage of dem indicator

##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

The execution result of the above code is:

[{"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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn