Anonymous user / 3.137.189.226 Log In Register
?
Wallet: 3.00
Daily Credits:
1.20 / 1.20

PHP Functions Online


json_encode

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

json_encodeReturns the JSON representation of a value

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

Checkout ? #

Item Description Item Price Your Price
Total

Preview #

${{ variable.param.name }} = {{ variable.param|getValue:variable.form:true }};
{{ call.result}} = ;

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 JSON_HEX_QUOT, JSON_HEX_TAG, JSON_HEX_AMP, JSON_HEX_APOS, JSON_NUMERIC_CHECK, JSON_BIGINT_AS_STRING, JSON_PRETTY_PRINT, JSON_UNESCAPED_SLASHES, JSON_FORCE_OBJECT, JSON_UNESCAPED_UNICODE.

Return Values #

Returns a JSON encoded string on success.

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}

Changelog #

Version Description
5.4.0 JSON_BIGINT_AS_STRING, JSON_PRETTY_PRINT, JSON_UNESCAPED_SLASHES, and JSON_UNESCAPED_UNICODE options were added.
5.3.3 JSON_NUMERIC_CHECK option was added.
5.3.0 The options parameter was added.

Notes #

Note:

In the event of a failure to encode, json_last_error() can be used to determine the exact nature of the error.

Note:

When encoding an array, if the keys are not a continuous numeric sequence starting from 0, all keys are encoded as strings, and specified explicitly for each key-value pair.

See Also #