Skip to main content
A data object can automatically be transformed into an array:
Which outputs:
By default, toArray recursively transforms all properties. Nested data objects, collections, and complex types like Carbon, DateTime, Enums will be transformed.

Without Transforming Properties

If you only want to transform a data object to an array without transforming the properties:

To JSON

You can also manually transform a data object to JSON:

Using Collections

Create a collection of data objects:
Transform the collection to an array:
Which outputs:

Nesting Data Objects

You can nest data objects within other data objects:
When transformed to an array:

Nesting Collections

You can also nest a collection of data objects:
Always type collections of data objects by annotation or the DataCollectionOf attribute. This is essential for correct transformation.

Hiding properties

You can hide specific properties from being included in the transformation using the Hidden attribute:
The password property will never be included when transforming the data object to an array or JSON:
The Hidden attribute is useful for excluding sensitive data like passwords, API tokens, or internal properties from API responses.