Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Utils.php

function Utils::jsonEncode

Wrapper for JSON encoding that throws when an error occurs.

Parameters

mixed $value The value being encoded:

int $options JSON encode option bitmask:

int $depth Set the maximum depth. Must be greater than zero.:

Throws

InvalidArgumentException if the JSON cannot be encoded.

See also

https://www.php.net/manual/en/function.json-encode.php

3 calls to Utils::jsonEncode()
Client::applyOptions in vendor/guzzlehttp/guzzle/src/Client.php
Applies the array of request options to a request.
FileCookieJar::save in vendor/guzzlehttp/guzzle/src/Cookie/FileCookieJar.php
Saves the cookies to a file.
json_encode in vendor/guzzlehttp/guzzle/src/functions.php
Wrapper for JSON encoding that throws when an error occurs.

File

vendor/guzzlehttp/guzzle/src/Utils.php, line 294

Class

Utils

Namespace

GuzzleHttp

Code

public static function jsonEncode($value, int $options = 0, int $depth = 512) : string {
    $json = \json_encode($value, $options, $depth);
    if (\JSON_ERROR_NONE !== \json_last_error()) {
        throw new InvalidArgumentException('json_encode error: ' . \json_last_error_msg());
    }
    
    /** @var string */
    return $json;
}
RSS feed
Powered by Drupal