> ## 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

> Map property names between different naming conventions like snake_case and camelCase using attributes and mappers.

Sometimes the property names in the array from which you're creating a data object might be different. You can define another name for a property when it is created from an array using attributes:

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

Creating the data object can now be done as such:

```php theme={null}
ContractData::from(['name' => 'Rick Astley', 'record_company' => 'RCA Records']);
```

## Using Mappers

Changing all property names in a data object to snake\_case in the data the object is created from can be done as such:

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

## Input and Output Mapping

You can also use the `MapName` attribute when you want to combine input (see [transforming data objects](/as-a-resource/mapping-property-names)) 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 Mapping Strategy

It is possible to set a default name mapping strategy for all data objects in the `data.php` config file:

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

## Mapping Nested Properties

You can also map nested properties using dot notation in the `MapInputName` attribute. This is useful when you want to extract a nested value from an array and assign it to a property in your data object:

```php theme={null}
class SongData extends Data
{
    public function __construct(
        #[MapInputName("title.name")]
        public string $title,
        #[MapInputName("artists.0.name")]
        public string $artist
    ) {
    }
}
```

You can create the data object from an array with nested structures:

```php theme={null}
SongData::from([
    "title" => [
        "name" => "Never gonna give you up"
    ],
    "artists" => [
        ["name" => "Rick Astley"]
    ]
]);
```

<Note>
  The package has a set of default mappers available, you can find them [here](/advanced-usage/available-property-mappers).
</Note>
