Title: _wp_prepare_json_schema_for_client_with_allowed_keywords
Published: August 20, 2026

---

# _wp_prepare_json_schema_for_client_with_allowed_keywords( $schema,  $allowed_keywords ): array<string,

## In this article

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

This function’s access is marked private. This means it is not intended for use 
by plugin or theme developers, only by core. It is listed here for completeness.

Prepares a JSON Schema for clients using a given keyword lookup.

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

true> $allowed_keywords Lookup map of allowed JSON Schema keywords.

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

 array<string, mixed> The prepared schema.

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

    ```php
    function _wp_prepare_json_schema_for_client_with_allowed_keywords( array $schema, array $allowed_keywords ): array {
    	if ( isset( $schema['type'] ) && 'object' === $schema['type'] && isset( $schema['default'] ) ) {
    		$default = $schema['default'];
    		if ( is_array( $default ) && empty( $default ) ) {
    			$schema['default'] = (object) $default;
    		}
    	}

    	$schema = array_intersect_key( $schema, $allowed_keywords );

    	/*
    	 * Collect draft-03 per-property `required: true` flags into a draft-04
    	 * `required` array of property names on the parent object schema.
    	 *
    	 * This mirrors rest_validate_object_value_from_schema(), where a draft-04
    	 * `required` array takes precedence: when one is present, per-property
    	 * booleans are ignored during validation. They are therefore left out of
    	 * the array here as well (but still stripped from the output) so the
    	 * published schema describes exactly what gets enforced.
    	 */
    	if ( isset( $schema['properties'] ) && is_array( $schema['properties'] ) ) {
    		$has_required_array = isset( $schema['required'] ) && is_array( $schema['required'] );
    		$required           = array();
    		foreach ( $schema['properties'] as $property => &$property_schema ) {
    			if ( is_array( $property_schema ) && ! wp_is_numeric_array( $property_schema ) && isset( $property_schema['required'] ) && is_bool( $property_schema['required'] ) ) {
    				if ( ! $has_required_array && true === $property_schema['required'] ) {
    					$required[] = (string) $property;
    				}
    				unset( $property_schema['required'] );
    			}
    		}
    		unset( $property_schema );

    		/*
    		 * Property keys are unique, so the collected list needs no deduplication.
    		 * When a draft-04 array is already present, leave it untouched.
    		 */
    		if ( ! $has_required_array && count( $required ) > 0 ) {
    			$schema['required'] = $required;
    		}
    	}

    	/*
    	 * A boolean `required` outside of an object's property list has no draft-04
    	 * equivalent, so drop it rather than emit an invalid keyword.
    	 */
    	if ( isset( $schema['required'] ) && is_bool( $schema['required'] ) ) {
    		unset( $schema['required'] );
    	}

    	/*
    	 * Sub-schema maps: keys are user-defined, values are sub-schemas.
    	 * Note: 'dependencies' values can also be property-dependency arrays
    	 * (numeric arrays of strings) which are skipped via wp_is_numeric_array().
    	 */
    	foreach ( array( 'properties', 'patternProperties', 'definitions', 'dependencies' ) as $keyword ) {
    		if ( isset( $schema[ $keyword ] ) && is_array( $schema[ $keyword ] ) ) {
    			foreach ( $schema[ $keyword ] as $key => $child_schema ) {
    				if ( is_array( $child_schema ) && ! wp_is_numeric_array( $child_schema ) ) {
    					$schema[ $keyword ][ $key ] = _wp_prepare_json_schema_for_client_with_allowed_keywords( $child_schema, $allowed_keywords );
    				}
    			}
    		}
    	}

    	// Single sub-schema keywords.
    	foreach ( array( 'not', 'additionalProperties', 'additionalItems' ) as $keyword ) {
    		if ( isset( $schema[ $keyword ] ) && is_array( $schema[ $keyword ] ) && ! wp_is_numeric_array( $schema[ $keyword ] ) ) {
    			$schema[ $keyword ] = _wp_prepare_json_schema_for_client_with_allowed_keywords( $schema[ $keyword ], $allowed_keywords );
    		}
    	}

    	// Items: single schema or tuple array of schemas.
    	if ( isset( $schema['items'] ) && is_array( $schema['items'] ) ) {
    		if ( ! wp_is_numeric_array( $schema['items'] ) ) {
    			$schema['items'] = _wp_prepare_json_schema_for_client_with_allowed_keywords( $schema['items'], $allowed_keywords );
    		} else {
    			foreach ( $schema['items'] as $index => $item_schema ) {
    				if ( is_array( $item_schema ) && ! wp_is_numeric_array( $item_schema ) ) {
    					$schema['items'][ $index ] = _wp_prepare_json_schema_for_client_with_allowed_keywords( $item_schema, $allowed_keywords );
    				}
    			}
    		}
    	}

    	// Array-of-schemas keywords.
    	foreach ( array( 'anyOf', 'oneOf', 'allOf' ) as $keyword ) {
    		if ( isset( $schema[ $keyword ] ) && is_array( $schema[ $keyword ] ) ) {
    			foreach ( $schema[ $keyword ] as $index => $sub_schema ) {
    				if ( is_array( $sub_schema ) && ! wp_is_numeric_array( $sub_schema ) ) {
    					$schema[ $keyword ][ $index ] = _wp_prepare_json_schema_for_client_with_allowed_keywords( $sub_schema, $allowed_keywords );
    				}
    			}
    		}
    	}

    	return $schema;
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/json-schema.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.1/src/wp-includes/json-schema.php#L106)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.1/src/wp-includes/json-schema.php#L106-L203)

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

| Uses | Description | 
| [_wp_prepare_json_schema_for_client_with_allowed_keywords()](https://developer.wordpress.org/reference/functions/_wp_prepare_json_schema_for_client_with_allowed_keywords/)`wp-includes/json-schema.php` |

Prepares a JSON Schema for clients using a given keyword lookup.

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

Determines if the variable is a numeric-indexed array.

  |

| Used by | Description | 
| [wp_prepare_json_schema_for_client()](https://developer.wordpress.org/reference/functions/wp_prepare_json_schema_for_client/)`wp-includes/json-schema.php` |

Prepares a JSON Schema for clients.

  | 
| [_wp_prepare_json_schema_for_client_with_allowed_keywords()](https://developer.wordpress.org/reference/functions/_wp_prepare_json_schema_for_client_with_allowed_keywords/)`wp-includes/json-schema.php` |

Prepares a JSON Schema for clients using a given keyword lookup.

  |

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

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

## User Contributed Notes

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