# NatsResponseJSONDeserializer

**Kind:** Class

**Source:** [`packages/microservices/deserializers/nats-response-json.deserializer.ts`](https://github.com/nestjs/nest/blob/master/packages/microservices/deserializers/nats-response-json.deserializer.ts#L12)

**Part of:** [Microservices](subsystem-packages-microservices)

`NatsResponseJSONDeserializer` converts NATS response records containing JSON payloads into the framework’s normalized `IncomingResponse` format. It extracts response metadata such as the correlation ID and disposal status so request-response clients can match replies to the originating request.

**Extends:** `IncomingResponseDeserializer`

## Methods

| Method | Signature | Returns |
|---|---|---|
| `deserialize` | `deserialize(value: Uint8Array, options: Record<string, any>)` | `IncomingResponse` |

## Diagram

```mermaid
graph LR
  A[NATS response record] --> B[NatsResponseJSONDeserializer]
  B --> C[Decode JSON response payload]
  B --> D[Read correlation and disposal headers]
  C --> E[IncomingResponse]
  D --> E
  E --> F[Client request-response handler]
```

## Usage

```ts
import { NatsResponseJSONDeserializer } from '@nestjs/microservices';

const deserializer = new NatsResponseJSONDeserializer();

// `natsResponse` is the record received from a NATS reply subscription.
const incomingResponse = deserializer.deserialize(natsResponse);

console.log(incomingResponse.id);         // Correlation ID for the request
console.log(incomingResponse.response);   // Decoded JSON payload
console.log(incomingResponse.isDisposed); // Whether the response stream ended
```

## AI Coding Instructions

- Use this deserializer for NATS request-response replies that contain JSON-encoded payloads.
- Preserve NATS response headers when creating or forwarding records; correlation and disposal metadata are required for correct request matching.
- Ensure response payloads are valid JSON before publishing them to NATS.
- Do not use this deserializer for arbitrary binary payloads; provide a custom deserializer when responses use another encoding.
- Keep the returned `IncomingResponse` shape compatible with the microservices client response-handling pipeline.

## Relationships

- IMPORTS → `loadPackage`
