---
title: "Memory Value Validation Helper"
canonical: "https://test.abhinandan.one/memory-json-value-helper"
markdown_url: "https://test.abhinandan.one/memory-json-value-helper.md"
publisher: "Primitive SDKs"
kind: "reference"
content_type: "reference"
category: "API Core / OpenAPI Generation"
description: "isMemoryJsonValue(value) returns true only if value is a valid JSON value: string, finite number, boolean, null, array, or plain object, recursively."
keywords: ["isMemoryJsonValue", "MemoryJsonValue", "@primitivedotdev/api-core", "client.memories.set", "Primitive Memories JSON value", "memory value validation"]
last_modified: "2026-08-11T18:55:07.377922+00:00"
published_at: "2026-08-11T18:55:07.222264+00:00"
sections:
  - {anchor: "what-it-does", title: "What it does"}
  - {anchor: "signature", title: "Signature"}
  - {anchor: "the-memoryjsonvalue-type", title: "The `MemoryJsonValue` type"}
  - {anchor: "what-is-accepted", title: "What is accepted"}
  - {anchor: "what-is-rejected", title: "What is rejected"}
  - {anchor: "where-its-used-internally", title: "Where it's used internally"}
  - {anchor: "example-guarding-a-value-before-storing-it", title: "Example: guarding a value before storing it"}
  - {anchor: "related-fix-in-codegen", title: "Related fix in codegen"}
  - {anchor: "next-steps", title: "Next steps"}
---

> Documentation index: https://test.abhinandan.one/llms.txt

# Memory Value Validation Helper

isMemoryJsonValue is a type-guard function that checks whether a value satisfies the JSON constraints Primitive Memories accepts, letting you validate data before calling client.memories.set.

## What it does

`isMemoryJsonValue` is a TypeScript type-guard function that checks whether an arbitrary JavaScript value conforms to the `MemoryJsonValue` type Primitive Memories accepts. Call it before writing a value with [`client.memories.set`](https://test.abhinandan.one/node-sdk-api-client.md) to fail fast on invalid input instead of getting a rejected API request.

It is defined in the workspace-internal [api-core](https://test.abhinandan.one/api-core-overview.md) package and reaches consumers through `@primitivedotdev/sdk/api`:

```typescript
import { isMemoryJsonValue } from "@primitivedotdev/sdk/api";

isMemoryJsonValue({ step: 2, done: false }); // true
isMemoryJsonValue(undefined); // false
```

> **Note:** Primitive Memories itself, the durable JSON key-value store behind `client.memories`, is documented on [Generated API Client and Primitive Memories](https://test.abhinandan.one/node-sdk-api-client.md). This page covers only the validation helper.

## Signature

```typescript
function isMemoryJsonValue(value: unknown): value is MemoryJsonValue;
```

| Parameter | Type | Description |
|---|---|---|
| `value` | `unknown` | The value to check. |

**Returns:** `boolean`. When `true`, TypeScript narrows `value` to `MemoryJsonValue` in the calling scope.

## The `MemoryJsonValue` type

```typescript
type MemoryJsonValue =
  | null
  | string
  | number
  | boolean
  | MemoryJsonValue[]
  | { [key: string]: MemoryJsonValue };
```

This is the exact type the generated OpenAPI client uses for the Memories API's `value` field. It is recursive: array elements and object property values must themselves be valid `MemoryJsonValue`s.

## What is accepted

| Input | Accepted? |
|---|---|
| `string` | Yes |
| Finite `number` | Yes |
| `boolean` | Yes |
| `null` | Yes |
| Array of valid `MemoryJsonValue`s | Yes |
| Plain object with valid `MemoryJsonValue` values | Yes |

## What is rejected

| Input | Rejected? | Why |
|---|---|---|
| `undefined` | Yes | Not representable in JSON |
| `bigint` | Yes | Not a JSON type |
| `symbol` | Yes | Not a JSON type |
| `function` | Yes | Not a JSON type |
| `NaN` / `Infinity` / `-Infinity` | Yes | Not finite numbers |
| Sparse arrays (holes) | Yes | A hole is not a valid element |
| Class instances (e.g. `Date`, `Map`, custom classes) | Yes | Not plain objects |
| Cyclic structures | Yes | Cannot serialize to JSON |

## Where it's used internally

The Node SDK's `client.memories.set` calls the same validation logic on its `value` field before sending the request, so a value that fails `isMemoryJsonValue` also fails at `client.memories.set` with a `TypeError`:

```text
client.memories.set value must be a JSON value: string, finite number, boolean,
null, array, or plain object. Undefined, bigint, symbol, function, NaN, Infinity,
sparse arrays, class instances, and cyclic values are not valid memory values.
```

Calling `isMemoryJsonValue` yourself lets you validate a value earlier in your code path, for example, before constructing the object you plan to store, or when accepting arbitrary data from an upstream source.

## Example: guarding a value before storing it

```typescript
import {
  createPrimitiveClient,
  isMemoryJsonValue,
} from "@primitivedotdev/sdk/api";

const client = createPrimitiveClient({ apiKey: process.env.PRIMITIVE_API_KEY! });

function toStorableState(candidate: unknown): Record<string, unknown> {
  if (!isMemoryJsonValue(candidate)) {
    throw new TypeError("state is not a valid Primitive Memories JSON value");
  }
  return candidate as Record<string, unknown>;
}

const state = toStorableState({ step: 2, lastEmailId: "em_123" });

await client.memories.set({ key: "thread:latest", value: state });
```

## Related fix in codegen

The generated `MemoryJsonValue` TypeScript type required a post-processing repair step during codegen, because `@hey-api/openapi-ts` widens the recursive `type: "null"` branch of the schema to `unknown`. See [Generated TypeScript Client Fixups](https://test.abhinandan.one/typescript-client-fixups.md) for how `fix-generated-api-imports.ts` patches this.
