# Newtonsoft.Json

**Kind:** Service

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

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

NuGet package dependency

`Newtonsoft.Json` is a NuGet package dependency declared by `Pams.Security.csproj` for JSON serialization and deserialization in the Pams.Security project. It converts .NET objects to JSON payloads and reads JSON input used by security-related components and integrations.

## Diagram

```mermaid
sequenceDiagram
    participant Client as JavaScript Client
    participant API as Pams.Security API
    participant Json as Newtonsoft.Json
    participant Model as .NET Security Model

    Client->>API: Send JSON request
    API->>Json: Deserialize request body
    Json->>Model: Create populated model
    Model-->>API: Return processed result
    API->>Json: Serialize response model
    Json-->>Client: Return JSON response
```

## Usage

```ts
type SecurityRequest = {
  userName: string;
  token: string;
};

async function validateSecurityRequest(request: SecurityRequest) {
  const response = await fetch("/api/security/validate", {
    method: "POST",
    headers: {
      "Content-Type": "application/json"
    },
    body: JSON.stringify(request)
  });

  if (!response.ok) {
    throw new Error("Security validation request failed.");
  }

  return response.json();
}

await validateSecurityRequest({
  userName: "example-user",
  token: "example-token"
});
```

## AI Coding Instructions

- Keep `Newtonsoft.Json` usage consistent with the serialization settings configured by the Pams.Security application.
- Check whether a model uses JSON attributes such as `JsonProperty` before renaming properties or changing payload shapes.
- Handle invalid or missing JSON input before passing deserialized values into security logic.
- Update `Pams.Security.csproj` when changing the NuGet package version or package reference configuration.
