# Newtonsoft.Json

**Kind:** Service

**Source:** `Pams/Core/Pams.Core/Pams.Core.csproj` (line 1)

**Part of:** [Pams](subsystem-pams)

NuGet package dependency

`Newtonsoft.Json` is a NuGet package dependency in `Pams.Core` for serializing objects to JSON and deserializing JSON into .NET types. It supports JSON handling for legacy-format data exchanged by PAMS Core components.

## Diagram

```mermaid
sequenceDiagram
    participant Caller
    participant PamsCore as Pams.Core
    participant Json as Newtonsoft.Json

    Caller->>PamsCore: Send JSON payload
    PamsCore->>Json: Deserialize payload
    Json-->>PamsCore: Return .NET object
    PamsCore->>Json: Serialize response object
    Json-->>PamsCore: Return JSON text
    PamsCore-->>Caller: Return JSON response
```

## Usage

```ts
type LegacyRecord = {
  reference: string;
  status: string;
};

async function sendLegacyRecord(record: LegacyRecord) {
  const response = await fetch("/pams-core/records", {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
    },
    body: JSON.stringify(record),
  });

  if (!response.ok) {
    throw new Error("Pams.Core rejected the JSON payload.");
  }

  return response.json();
}

await sendLegacyRecord({
  reference: "PAMS-REQUEST",
  status: "Pending",
});
```

## AI Coding Instructions

- Keep `Newtonsoft.Json` references within `Pams.Core` code that reads or writes JSON payloads.
- Preserve JSON property names and shapes expected by legacy-format integrations.
- Check null handling and missing fields when deserializing external JSON.
- Do not replace `Newtonsoft.Json` with another serializer without checking legacy JSON behavior and dependent integrations.
