PHP | json_decode() Function Last Updated : 09 May, 2019 Comments Improve Suggest changes Like Article Like Report The json_decode() function is an inbuilt function in PHP which is used to decode a JSON string. It converts a JSON encoded string into a PHP variable. Syntax: json_decode( $json, $assoc = FALSE, $depth = 512, $options = 0 ) Parameters: This function accepts four parameters as mentioned above and described below: json: It holds the JSON string which need to be decode. It only works with UTF-8 encoded strings. assoc: It is a boolean variable. If it is true then objects returned will be converted into associative arrays. depth: It states the recursion depth specified by user. options: It includes bitmask of JSON_OBJECT_AS_ARRAY, JSON_BIGINT_AS_STRING,, JSON_THROW_ON_ERROR. Return values: This function returns the encoded JSON value in appropriate PHP type. If the json cannot be decoded or if the encoded data is deeper than the recursion limit then it returns NULL. Below examples illustrate the use of json_decode() function in PHP: Example 1: php <?php // Declare a json string $json = '{"g":7, "e":5, "e":5, "k":11, "s":19}'; // Use json_decode() function to // decode a string var_dump(json_decode($json)); var_dump(json_decode($json, true)); ?> Output: object(stdClass)#1 (4) { ["g"]=> int(7) ["e"]=> int(5) ["k"]=> int(11) ["s"]=> int(19) } array(4) { ["g"]=> int(7) ["e"]=> int(5) ["k"]=> int(11) ["s"]=> int(19) } Example 2: php <?php // Declare a json string $json = '{"geeks": 7551119}'; // Use json_decode() function to // decode a string $obj = json_decode($json); // Display the value of json object print $obj->{'geeks'}; ?> Output: 7551119 Common Errors while using json_decode() function: Used strings are valid JavaScript but not valid JSON. Name and value must be enclosed in double quotes, single quotes are not allowed. Trailing commas are not allowed. Reference: http://php.net/manual/en/function.json-decode.php Comment More infoAdvertise with us Next Article PHP | json_decode() Function C Code_Mech Follow Improve Article Tags : Web Technologies PHP PHP-function Similar Reads PHP | json_encode() Function The json_encode() function is an inbuilt function in PHP which is used to convert PHP array or object into JSON representation. Syntax : string json_encode( $value, $option, $depth ) Parameters: $value: It is a mandatory parameter which defines the value to be encoded. $option: It is optional parame 2 min read PHP | utf8_decode() Function The utf8_decode() function is an inbuilt function in PHP which is used to decode a UTF-8 string to the ISO-8859-1. This function decodes back to the encoded string which is encoded with the utf8_encode() function. Syntax:Â string utf8_decode( string $string ) Parameter: This function accepts single 2 min read PHP decoct( ) Function In the earlier days of computing, octal numbers and the octal numbering system was very popular for counting inputs and outputs because as it works in counts of eight, inputs and outputs were in counts of eight, a byte at a time. Due to a wide usage of octal number system many times it happens that 2 min read PHP | base64_decode() Function The base64_decode() is an inbuilt function in PHP which is used to Decodes data which is encoded in MIME base64.Syntax: string base64_decode( $data, $strict ) Parameters: This function accepts two parameter as mentioned above and described below: $data: It is mandatory parameter which contains the e 1 min read PHP | DsVector jsonSerialize() Function The Ds\Vector::jsonSerialize() function is an inbuilt function in PHP which is used to return the element which can be converted to JSON. Syntax: mixed public JsonSerializable::jsonSerialize( void ) Parameters: This function does not accepts any parameter. Return Value: This function returns the val 1 min read How to JSON Decode in PHP? JSON Decode is the process of converting a JSON string into a PHP variable, typically an object or an associative array. Then we will print that decode JSON text. Below are the approaches to JSON decoding in PHP: Table of Content Using json_decode() methodUsing Explode and Foreach LoopUsing json_dec 2 min read PHP | iconv_get_encoding() Function The iconv_get_encoding() function is an inbuilt function in PHP which is used to retrieve the internal configuration variables of iconv extension. Syntax: mixed iconv_get_encoding( $type = "all" ) Parameters: This function accepts single parameter $type. The value of $type parameter are: all input_e 1 min read PHP each() Function The each() function is an inbuilt function in PHP and is used to get the current element key-value pair of the given array to which the internal pointer is currently pointing. After returning the key and value of the current element the internal pointer is incremented by one in the array. Note: You 2 min read PHP | base64_encode() Function The base64_encode() function is an inbuilt function in PHP that is used to encode data with MIME base64. MIME (Multipurpose Internet Mail Extensions) base64 is used to encode the string in base64. The base64_encoded data takes 33% more space than the original data. Syntax: string base64_encode( $dat 1 min read PHP openssl_digest() Function The openssl_digest() function is an inbuilt function in PHP that is used to compute a digest hash value for the given data using a given method and returns a raw or binary hex-encoded string. Syntax: openssl_digest( string $data, string $digest_algo, bool $binary = false): string|false Parameters: T 2 min read Like