PYTHON json_encode

is this article helpful?
|
Python replacement for PHP's json_encode [ edit | history ]
# Python 2.6+
import json
result = json.dumps(value)
or
# Python 2.6+
import json
json.dump(value, out_file)

PHP json_encode

PHP original manual for json_encode [ show | php.net ]

json_encode

(PHP 5 >= 5.2.0, PECL json >= 1.2.0)

json_encodeReturns the JSON representation of a value

Description

string json_encode ( mixed $value [, int $options= 0 ] )

Returns a string containing the JSON representation of value .

Parameters

value

The value being encoded. Can be any type except a resource.

This function only works with UTF-8 encoded data.

options

Bitmask consisting of PHP_JSON_HEX_QUOT, PHP_JSON_HEX_TAG, PHP_JSON_HEX_AMP, PHP_JSON_HEX_APOS. Defaults to 0.

Return Values

Returns a JSON encoded string on success.

Changelog

Version Description
5.2.1 Added support to JSON encode basic types

Examples

Example #1 A json_encode() example

<?php
$arr 
= array ('a'=>1,'b'=>2,'c'=>3,'d'=>4,'e'=>5);

echo 
json_encode($arr);
?>

The above example will output:

{"a":1,"b":2,"c":3,"d":4,"e":5}

See Also