Sha256: 2ccf4b4d5914a22ef685fc05105d6fb9c07ca6dfba89c780ccf5cf5c79c8e3a4

Contents?: true

Size: 951 Bytes

Versions: 15

Compression:

Stored size: 951 Bytes

Contents

[Back to Guides](../README.md)

# Key Transforms

Key Transforms modify the casing of keys and keys referenced in values in
serialized responses.

Provided key transforms:

| Option | Result |
|----|----|
| `:camel` | ExampleKey |
| `:camel_lower` | exampleKey |
| `:dash` | example-key |
| `:unaltered` | the original, unaltered key |
| `:underscore` | example_key |
| `nil` | use the adapter default |

Key translation precedence is as follows:

##### Adapter option

`key_transform` is provided as an option via render.

```render json: posts, each_serializer: PostSerializer, key_transform: :camel_lower```

##### Configuration option

`key_transform` is set in `ActiveModelSerializers.config.key_transform`.

```ActiveModelSerializers.config.key_transform = :camel_lower```

##### Adapter default

Each adapter has a default transform configured:

| Adapter | Default Key Transform |
|----|----|
| `Json` | `:unaltered` |
| `JsonApi` | `:dash` |

Version data entries

15 entries across 15 versions & 3 rubygems

Version Path
active_model_serializers_custom-0.10.90 docs/general/key_transforms.md
active_model_serializers-0.10.9 docs/general/key_transforms.md
active_model_serializers-0.10.8 docs/general/key_transforms.md
active_model_serializers-0.10.7 docs/general/key_transforms.md
active_model_serializers-0.10.6 docs/general/key_transforms.md
active_model_serializers-0.10.5 docs/general/key_transforms.md
active_model_serializers-0.10.4 docs/general/key_transforms.md
agi_active_model_serializers-0.10.9 docs/general/key_transforms.md
agi_active_model_serializers-0.10.8 docs/general/key_transforms.md
agi_active_model_serializers-0.10.7 docs/general/key_transforms.md
active_model_serializers-0.10.3 docs/general/key_transforms.md
active_model_serializers-0.10.2 docs/general/key_transforms.md
active_model_serializers-0.10.1 docs/general/key_transforms.md
active_model_serializers-0.10.0 docs/general/key_transforms.md
active_model_serializers-0.10.0.rc5 docs/general/key_transforms.md