public static function decode($value, $assoc = false)
    {
        $data = json_decode((string) $value, $assoc);

        switch (json_last_error()) {
            case JSON_ERROR_NONE:
                return $data;
                break;

            case JSON_ERROR_DEPTH:
                throw new \RuntimeException('Invalid JSON structure');
                break;

            case JSON_ERROR_STATE_MISMATCH:
            case JSON_ERROR_CTRL_CHAR:
            case JSON_ERROR_SYNTAX:
            default:
                throw new \RuntimeException('Syntax error, malformed JSON');
                break;
        }
    }