---
id: projected-names
title: Projected names
---

# Projected Names

:::warning
Projected names is a legacy feature and will be phased out. Please use [Encoded Names](encoded-names.md) instead for changing the name over the wire.
:::

There is some cases where the name you have in TypeSpec might differ from the name over the wire or for a certain language.

## Known targets

List of known targets.

- Wire:
  - `json`: Configure JSON representation of data
  - `xml`: Configure XML representation of data
- Language:
  - `csharp`: Configure C# code generation
  - `java`: Configure Java code generation
  - `python`: Configure Python code generation
  - `javascript`: Configure JavaScript code generation
  - `swift` : Configure Swift code generation
  - `c` : Configure C code generation
- Type:
  - `client`: Configure output for the client
  - `server`: Configure output for the server

## Update name for a given target

### With decorator

To update the name of a TypeSpec entity you can use the `@projectedName` decorator. This decorator takes 2 parameters:

- `string` target name. See [known targets](#known-targets)
- `string` projected name. Whatever the name should be in the given target.

Example:

```typespec
model Foo {
  // Specify that when serializing to JSON `expireAt` property should be named `exp`
  @projectedName("json", "exp")
  expireAt: string;
}
```

### With projection

The decorator is just a syntax sugar for the `target` projection behind the scenes. In more complex cases you might want to just implement the projection manually.

```typespec
model Foo {
  expireAt: string;
}

projection Foo#target {
  to(targetName) {
    if targetName == "json" {
      self::rename("exp");
    };
  }
}
```

## Example

```typespec
model CertificateAttributes {
  @projectedName("json", "nbf")
  @projectedName("csharp", "ValidAfter")
  notBefore: int32;

  @projectedName("json", "exp")
  expires: int32;

  @projectedName("client", "createdAt")
  created: int32;

  updated: int32;
}
```

<table>
<thead>
<tr>
<th>Json</th>
<th>Typescript</th>
<th>CSharp</th>
</tr>
</thead>
<tr>
<td>When serialized to Json property use the json projected name</td>
<td>Typescript didn't provide any projected name so it keep the model as it is.</td>
<td>Model uses the `csharp` projected names and keeps the reference to the JSON name in JsonProperty</td>
</tr>
<tr>
<td>

```json
{
  "nbf": 1430344421,
  "exp": 2208988799,
  "created": 1493938289,
  "updated": 1493938291
}
```

</td>
<td>

```ts
interface Attributes {
  notBefore: number;
  expires: number;
  createdAt: number;
  updated: number;
}
```

</td>

<td>

```cs
class CertificateAttributes
{
  [JsonProperty("nbf")]
  public int ValidAfter {get; set;}

  [JsonProperty("exp")]
  public int Expires {get; set;}

  [JsonProperty("created")]
  public int CreatedAt {get; set;}

  public int Updated {get; set;}
}
```

</td>
</tr>
</table>
