You are here

public static function JWT::jsonDecode in Auth0 Single Sign On 8.2

Decode a JSON string into a PHP object.

Parameters

string $input JSON string:

Return value

object Object representation of JSON string

Throws

DomainException Provided string was invalid JSON

2 calls to JWT::jsonDecode()
JWT::decode in vendor/firebase/php-jwt/src/JWT.php
Decodes a JWT string into a PHP object.
JWTVerifier::decodeTokenSegment in vendor/auth0/auth0-php/src/JWTVerifier.php
Base64 and JSON decode a string.

File

vendor/firebase/php-jwt/src/JWT.php, line 280

Class

JWT
JSON Web Token implementation, based on this spec: https://tools.ietf.org/html/rfc7519

Namespace

Firebase\JWT

Code

public static function jsonDecode($input) {
  if (\version_compare(PHP_VERSION, '5.4.0', '>=') && !(\defined('JSON_C_VERSION') && PHP_INT_SIZE > 4)) {

    /** In PHP >=5.4.0, json_decode() accepts an options parameter, that allows you
     * to specify that large ints (like Steam Transaction IDs) should be treated as
     * strings, rather than the PHP default behaviour of converting them to floats.
     */
    $obj = \json_decode($input, false, 512, JSON_BIGINT_AS_STRING);
  }
  else {

    /** Not all servers will support that, however, so for older versions we must
     * manually detect large ints in the JSON string and quote them (thus converting
     *them to strings) before decoding, hence the preg_replace() call.
     */
    $max_int_length = \strlen((string) PHP_INT_MAX) - 1;
    $json_without_bigints = \preg_replace('/:\\s*(-?\\d{' . $max_int_length . ',})/', ': "$1"', $input);
    $obj = \json_decode($json_without_bigints);
  }
  if ($errno = \json_last_error()) {
    static::handleJsonError($errno);
  }
  elseif ($obj === null && $input !== 'null') {
    throw new DomainException('Null result with non-null input');
  }
  return $obj;
}