Title: WP_Theme_JSON_Data
Published: November 2, 2022
Last modified: August 20, 2026

---

# class WP_Theme_JSON_Data {}

## In this article

 * [Methods](https://developer.wordpress.org/reference/classes/wp_theme_json_data/?output_format=md#methods)
 * [Source](https://developer.wordpress.org/reference/classes/wp_theme_json_data/?output_format=md#source)

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

Class to provide access to update a theme.json structure.

## 󠀁[Methods](https://developer.wordpress.org/reference/classes/wp_theme_json_data/?output_format=md#methods)󠁿

| Name | Description | 
| [WP_Theme_JSON_Data::__construct](https://developer.wordpress.org/reference/classes/wp_theme_json_data/__construct/) | Constructor. | 
| [WP_Theme_JSON_Data::get_data](https://developer.wordpress.org/reference/classes/wp_theme_json_data/get_data/) | Returns an array containing the underlying data following the theme.json specification. | 
| [WP_Theme_JSON_Data::get_theme_json](https://developer.wordpress.org/reference/classes/wp_theme_json_data/get_theme_json/) | Returns theme JSON object. | 
| [WP_Theme_JSON_Data::update_with](https://developer.wordpress.org/reference/classes/wp_theme_json_data/update_with/) | Updates the theme.json with the given data. |

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

    ```php
    #[AllowDynamicProperties]
    class WP_Theme_JSON_Data {

    	/**
    	 * Container of the data to update.
    	 *
    	 * @since 6.1.0
    	 * @var WP_Theme_JSON
    	 */
    	private $theme_json = null;

    	/**
    	 * The origin of the data: default, theme, user, etc.
    	 *
    	 * @since 6.1.0
    	 * @var string
    	 */
    	private $origin = '';

    	/**
    	 * Constructor.
    	 *
    	 * @since 6.1.0
    	 *
    	 * @link https://developer.wordpress.org/block-editor/reference-guides/theme-json-reference/
    	 *
    	 * @param array  $data   Array following the theme.json specification.
    	 * @param string $origin The origin of the data: default, theme, user.
    	 */
    	public function __construct( $data = array( 'version' => WP_Theme_JSON::LATEST_SCHEMA ), $origin = 'theme' ) {
    		$this->origin     = $origin;
    		$this->theme_json = new WP_Theme_JSON( $data, $this->origin );
    	}

    	/**
    	 * Updates the theme.json with the given data.
    	 *
    	 * @since 6.1.0
    	 *
    	 * @param array $new_data Array following the theme.json specification.
    	 *
    	 * @return WP_Theme_JSON_Data The own instance with access to the modified data.
    	 */
    	public function update_with( $new_data ) {
    		$this->theme_json->merge( new WP_Theme_JSON( $new_data, $this->origin ) );
    		return $this;
    	}

    	/**
    	 * Returns an array containing the underlying data
    	 * following the theme.json specification.
    	 *
    	 * @since 6.1.0
    	 *
    	 * @return array
    	 */
    	public function get_data() {
    		return $this->theme_json->get_raw_data();
    	}

    	/**
    	 * Returns theme JSON object.
    	 *
    	 * @since 6.6.0
    	 *
    	 * @return WP_Theme_JSON The theme JSON structure stored in this data object.
    	 */
    	public function get_theme_json() {
    		return $this->theme_json;
    	}
    }
    ```

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

## User Contributed Notes

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