Automattic\WooCommerce\Vendor\GraphQL\Server

OperationParams::decodeIfJSONprotected staticWC 1.0

Decodes the value if it is JSON, otherwise returns it unchanged.

Method of the class: OperationParams{}

No Hooks.

Returns

Mixed.

Usage

$result = OperationParams::decodeIfJSON( $value );
$value(mixed) (required)
.

OperationParams::decodeIfJSON() code WC 10.8.1

protected static function decodeIfJSON($value)
{
    if (! is_string($value)) {
        return $value;
    }

    $decoded = json_decode($value, true);
    if (json_last_error() === \JSON_ERROR_NONE) {
        return $decoded;
    }

    return $value;
}