Title: AbstractDataTransferObject::jsonSerialize
Published: May 20, 2026

---

# AbstractDataTransferObject::jsonSerialize(): mixed

## In this article

 * [Description](https://developer.wordpress.org/reference/classes/wordpress-aiclient-common-abstractdatatransferobject/jsonserialize/?output_format=md#description)
 * [Return](https://developer.wordpress.org/reference/classes/wordpress-aiclient-common-abstractdatatransferobject/jsonserialize/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/classes/wordpress-aiclient-common-abstractdatatransferobject/jsonserialize/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/classes/wordpress-aiclient-common-abstractdatatransferobject/jsonserialize/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/classes/wordpress-aiclient-common-abstractdatatransferobject/jsonserialize/?output_format=md#changelog)

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

Converts the object to a JSON-serializable format.

## 󠀁[Description](https://developer.wordpress.org/reference/classes/wordpress-aiclient-common-abstractdatatransferobject/jsonserialize/?output_format=md#description)󠁿

This method uses the toArray() method and then processes the result based on the
JSON schema to ensure proper object representation for empty arrays.

## 󠀁[Return](https://developer.wordpress.org/reference/classes/wordpress-aiclient-common-abstractdatatransferobject/jsonserialize/?output_format=md#return)󠁿

 mixed The JSON-serializable representation.

## 󠀁[Source](https://developer.wordpress.org/reference/classes/wordpress-aiclient-common-abstractdatatransferobject/jsonserialize/?output_format=md#source)󠁿

    ```php
    #[\ReturnTypeWillChange]
    public function jsonSerialize()
    {
        $data = $this->toArray();
        $schema = static::getJsonSchema();
        return $this->convertEmptyArraysToObjects($data, $schema);
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/php-ai-client/src/common/abstractdatatransferobject.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.0/src/wp-includes/php-ai-client/src/Common/AbstractDataTransferObject.php#L77)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.0/src/wp-includes/php-ai-client/src/Common/AbstractDataTransferObject.php#L77-L83)

## 󠀁[Related](https://developer.wordpress.org/reference/classes/wordpress-aiclient-common-abstractdatatransferobject/jsonserialize/?output_format=md#related)󠁿

| Uses | Description | 
| [AbstractDataTransferObject::convertEmptyArraysToObjects()](https://developer.wordpress.org/reference/classes/wordpress-aiclient-common-abstractdatatransferobject/convertemptyarraystoobjects/)`wp-includes/php-ai-client/src/Common/AbstractDataTransferObject.php` |

Recursively converts empty arrays to stdClass objects where the schema expects objects.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/classes/wordpress-aiclient-common-abstractdatatransferobject/jsonserialize/?output_format=md#changelog)󠁿

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

## User Contributed Notes

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