> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/spatie/laravel-data/llms.txt
> Use this file to discover all available pages before exploring further.

# Mapping Property Names

> Transform property names between camelCase and snake_case in API responses

Sometimes you want to change the name of a property in the transformed payload. You can do this with attributes:

```php theme={null}
class ContractData extends Data
{
    public function __construct(
        public string $name,
        #[MapOutputName('record_company')]
        public string $recordCompany,
    ) {
    }
}
```

Transformed output:

```php theme={null}
[
    'name' => 'Rick Astley',
    'record_company' => 'RCA Records',
]
```

## Class-Level Mapping

Change all property names in a data object to snake\_case:

```php theme={null}
#[MapOutputName(SnakeCaseMapper::class)]
class ContractData extends Data
{
    public function __construct(
        public string $name,
        public string $recordCompany,
    ) {
    }
}
```

## Input and Output Mapping

Use the `MapName` attribute to combine input and output property name mapping:

```php theme={null}
#[MapName(SnakeCaseMapper::class)]
class ContractData extends Data
{
    public function __construct(
        public string $name,
        public string $recordCompany,
    ) {
    }
}
```

## Global Name Mapping

Set a default name mapping strategy for all data objects in `config/data.php`:

```php theme={null}
'name_mapping_strategy' => [
    'input' => null,
    'output' => SnakeCaseMapper::class,
],
```

Now all data objects will automatically map property names to snake\_case in the output:

<Tabs>
  <Tab title="Data Object">
    ```php theme={null}
    $contract = new ContractData(
        name: 'Rick Astley',
        recordCompany: 'RCA Records',
    );
    ```
  </Tab>

  <Tab title="Transformed Output">
    ```php theme={null}
    [
        'name' => 'Rick Astley',
        'record_company' => 'RCA Records',
    ]
    ```
  </Tab>
</Tabs>

## Available Mappers

The package includes several built-in mappers:

* `SnakeCaseMapper` - Converts to snake\_case
* `CamelCaseMapper` - Converts to camelCase
* `StudlyCaseMapper` - Converts to StudlyCase
* `KebabCaseMapper` - Converts to kebab-case

<Note>
  For a complete list of available property mappers, see the [advanced usage documentation](/advanced-usage/available-property-mappers).
</Note>
