Title: rest_sanitize_object
Published: August 11, 2020
Last modified: February 24, 2026

---

# rest_sanitize_object( mixed $maybe_object ): array

## In this article

 * [Parameters](https://developer.wordpress.org/reference/functions/rest_sanitize_object/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/rest_sanitize_object/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/rest_sanitize_object/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/rest_sanitize_object/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/rest_sanitize_object/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/functions/rest_sanitize_object/?output_format=md#wp--skip-link--target)

Converts an object-like value to an array.

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/rest_sanitize_object/?output_format=md#parameters)󠁿

 `$maybe_object`mixedrequired

The value being evaluated.

## 󠀁[Return](https://developer.wordpress.org/reference/functions/rest_sanitize_object/?output_format=md#return)󠁿

 array Returns the object extracted from the value as an associative array.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/rest_sanitize_object/?output_format=md#source)󠁿

    ```php
    function rest_sanitize_object( $maybe_object ) {
    	if ( '' === $maybe_object ) {
    		return array();
    	}

    	if ( $maybe_object instanceof stdClass ) {
    		return (array) $maybe_object;
    	}

    	if ( $maybe_object instanceof JsonSerializable ) {
    		$maybe_object = $maybe_object->jsonSerialize();
    	}

    	if ( ! is_array( $maybe_object ) ) {
    		return array();
    	}

    	return $maybe_object;
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/rest-api.php#L1641)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/rest-api.php#L1641-L1659)

## 󠀁[Related](https://developer.wordpress.org/reference/functions/rest_sanitize_object/?output_format=md#related)󠁿

| Used by | Description | 
| [rest_validate_object_value_from_schema()](https://developer.wordpress.org/reference/functions/rest_validate_object_value_from_schema/)`wp-includes/rest-api.php` |

Validates an object value based on a schema.

  | 
| [rest_sanitize_value_from_schema()](https://developer.wordpress.org/reference/functions/rest_sanitize_value_from_schema/)`wp-includes/rest-api.php` |

Sanitize a value based on a schema.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/rest_sanitize_object/?output_format=md#changelog)󠁿

| Version | Description | 
| [5.5.0](https://developer.wordpress.org/reference/since/5.5.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Frest_sanitize_object%2F)
before being able to contribute a note or feedback.