# deserializePriorityQueueJson

## Call Signature

> **deserializePriorityQueueJson**(`payload`, `keyOrder`): [`DenseIntegerPriorityQueue`](/reference/knotkit/heap/interfaces/denseintegerpriorityqueue/)

Defined in: [packages/heap/src/serialization/families/priority-queue.ts:193](https://github.com/jkomyno/knotkit/blob/ef04dc6fd5182dca281abddf3e1dcb13118c15a4/packages/heap/src/serialization/families/priority-queue.ts#L193)

Rebuild a priority queue from a [SerializedPriorityQueue](/reference/knotkit/heap/wire/type-aliases/serializedpriorityqueue/). O(n) time: one validation pass plus one entry copy — the layout is adopted exactly, never reheapified, and the value-to-index overlay is rebuilt in a single sweep.

Serialization is comparator-blind: pass the **base key order used at construction** — the direction comes from the payload’s `kind`. Round-trip fidelity holds when the re-supplied order is semantically equivalent to the original; a different order that happens to satisfy the payload’s layout is accepted, and the restored queue then follows the order actually supplied. Comparator identity is the caller’s responsibility — a documented limitation, not a validated fact.

Validation covers shape, kind, arity, per-entry `[key, value]` pair shape, duplicate values (the overlay requires unique values), the full heap invariant over keys under the direction-adjusted supplied order, and — with `options` — every key and value; guards run before the order is ever invoked.

### Parameters

#### payload

[`SerializedDenseIntegerPriorityQueue`](/reference/knotkit/heap/wire/interfaces/serializeddenseintegerpriorityqueue/)

A statically typed serialized priority queue, or decoded `unknown` paired with runtime key and value validation.

#### keyOrder

[`Order`](/reference/knotkit/heap/type-aliases/order/)<`number`>

The base key order the queue was constructed under.

### Returns

[`DenseIntegerPriorityQueue`](/reference/knotkit/heap/interfaces/denseintegerpriorityqueue/)

### Throws

When the payload is malformed or fails validation: not an object (`INVALID_SHAPE`), a missing or unsupported schema version (`UNSUPPORTED_SCHEMA_VERSION`), an unknown or cross-family `kind` (`UNKNOWN_KIND`), a missing or mistyped `entries` array (`MISSING_ENTRIES`), an unsafe or missing k-ary `arity` (`INVALID_ARITY`), an entry that is not a `[key, value]` pair (`INVALID_SHAPE`, naming the index), a key or value failing its guard (`INVALID_KEY`/`INVALID_VALUE`), a duplicate value (`DUPLICATE_VALUE`), or a parent-child key pair violating the heap invariant (`HEAP_INVARIANT_VIOLATION`, naming the offending entry index).

## Call Signature

> **deserializePriorityQueueJson**<`K`, `V`>(`payload`, `keyOrder`): [`PriorityQueue`](/reference/knotkit/heap/type-aliases/priorityqueue/)<`K`, `V`>

Defined in: [packages/heap/src/serialization/families/priority-queue.ts:197](https://github.com/jkomyno/knotkit/blob/ef04dc6fd5182dca281abddf3e1dcb13118c15a4/packages/heap/src/serialization/families/priority-queue.ts#L197)

Rebuild a priority queue from a [SerializedPriorityQueue](/reference/knotkit/heap/wire/type-aliases/serializedpriorityqueue/). O(n) time: one validation pass plus one entry copy — the layout is adopted exactly, never reheapified, and the value-to-index overlay is rebuilt in a single sweep.

Serialization is comparator-blind: pass the **base key order used at construction** — the direction comes from the payload’s `kind`. Round-trip fidelity holds when the re-supplied order is semantically equivalent to the original; a different order that happens to satisfy the payload’s layout is accepted, and the restored queue then follows the order actually supplied. Comparator identity is the caller’s responsibility — a documented limitation, not a validated fact.

Validation covers shape, kind, arity, per-entry `[key, value]` pair shape, duplicate values (the overlay requires unique values), the full heap invariant over keys under the direction-adjusted supplied order, and — with `options` — every key and value; guards run before the order is ever invoked.

### Type Parameters

#### K

`K`

#### V

`V`

### Parameters

#### payload

[`SerializedPriorityQueue`](/reference/knotkit/heap/wire/type-aliases/serializedpriorityqueue/)<`K`, `V`>

A statically typed serialized priority queue, or decoded `unknown` paired with runtime key and value validation.

#### keyOrder

[`Order`](/reference/knotkit/heap/type-aliases/order/)<`K`>

The base key order the queue was constructed under.

### Returns

[`PriorityQueue`](/reference/knotkit/heap/type-aliases/priorityqueue/)<`K`, `V`>

### Throws

When the payload is malformed or fails validation: not an object (`INVALID_SHAPE`), a missing or unsupported schema version (`UNSUPPORTED_SCHEMA_VERSION`), an unknown or cross-family `kind` (`UNKNOWN_KIND`), a missing or mistyped `entries` array (`MISSING_ENTRIES`), an unsafe or missing k-ary `arity` (`INVALID_ARITY`), an entry that is not a `[key, value]` pair (`INVALID_SHAPE`, naming the index), a key or value failing its guard (`INVALID_KEY`/`INVALID_VALUE`), a duplicate value (`DUPLICATE_VALUE`), or a parent-child key pair violating the heap invariant (`HEAP_INVARIANT_VIOLATION`, naming the offending entry index).

## Call Signature

> **deserializePriorityQueueJson**<`K`, `V`>(`payload`, `keyOrder`, `options`): [`PriorityQueue`](/reference/knotkit/heap/type-aliases/priorityqueue/)<`K`, `V`>

Defined in: [packages/heap/src/serialization/families/priority-queue.ts:201](https://github.com/jkomyno/knotkit/blob/ef04dc6fd5182dca281abddf3e1dcb13118c15a4/packages/heap/src/serialization/families/priority-queue.ts#L201)

Rebuild a priority queue from a [SerializedPriorityQueue](/reference/knotkit/heap/wire/type-aliases/serializedpriorityqueue/). O(n) time: one validation pass plus one entry copy — the layout is adopted exactly, never reheapified, and the value-to-index overlay is rebuilt in a single sweep.

Serialization is comparator-blind: pass the **base key order used at construction** — the direction comes from the payload’s `kind`. Round-trip fidelity holds when the re-supplied order is semantically equivalent to the original; a different order that happens to satisfy the payload’s layout is accepted, and the restored queue then follows the order actually supplied. Comparator identity is the caller’s responsibility — a documented limitation, not a validated fact.

Validation covers shape, kind, arity, per-entry `[key, value]` pair shape, duplicate values (the overlay requires unique values), the full heap invariant over keys under the direction-adjusted supplied order, and — with `options` — every key and value; guards run before the order is ever invoked.

### Type Parameters

#### K

`K`

#### V

`V`

### Parameters

#### payload

`unknown`

A statically typed serialized priority queue, or decoded `unknown` paired with runtime key and value validation.

#### keyOrder

[`Order`](/reference/knotkit/heap/type-aliases/order/)<`K`>

The base key order the queue was constructed under.

#### options

[`DeserializePriorityQueueJsonOptions`](/reference/knotkit/heap/wire/interfaces/deserializepriorityqueuejsonoptions/)<`K`, `V`>

Runtime decoding options for payloads whose key and value types are not yet known.

### Returns

[`PriorityQueue`](/reference/knotkit/heap/type-aliases/priorityqueue/)<`K`, `V`>

### Throws

When the payload is malformed or fails validation: not an object (`INVALID_SHAPE`), a missing or unsupported schema version (`UNSUPPORTED_SCHEMA_VERSION`), an unknown or cross-family `kind` (`UNKNOWN_KIND`), a missing or mistyped `entries` array (`MISSING_ENTRIES`), an unsafe or missing k-ary `arity` (`INVALID_ARITY`), an entry that is not a `[key, value]` pair (`INVALID_SHAPE`, naming the index), a key or value failing its guard (`INVALID_KEY`/`INVALID_VALUE`), a duplicate value (`DUPLICATE_VALUE`), or a parent-child key pair violating the heap invariant (`HEAP_INVARIANT_VIOLATION`, naming the offending entry index).

## Call Signature

> **deserializePriorityQueueJson**(`payload`, `keyOrder`): [`DenseIntegerPriorityQueue`](/reference/knotkit/heap/interfaces/denseintegerpriorityqueue/) | [`PriorityQueue`](/reference/knotkit/heap/type-aliases/priorityqueue/)<`unknown`, `unknown`>

Defined in: [packages/heap/src/serialization/families/priority-queue.ts:206](https://github.com/jkomyno/knotkit/blob/ef04dc6fd5182dca281abddf3e1dcb13118c15a4/packages/heap/src/serialization/families/priority-queue.ts#L206)

Rebuild a priority queue from a [SerializedPriorityQueue](/reference/knotkit/heap/wire/type-aliases/serializedpriorityqueue/). O(n) time: one validation pass plus one entry copy — the layout is adopted exactly, never reheapified, and the value-to-index overlay is rebuilt in a single sweep.

Serialization is comparator-blind: pass the **base key order used at construction** — the direction comes from the payload’s `kind`. Round-trip fidelity holds when the re-supplied order is semantically equivalent to the original; a different order that happens to satisfy the payload’s layout is accepted, and the restored queue then follows the order actually supplied. Comparator identity is the caller’s responsibility — a documented limitation, not a validated fact.

Validation covers shape, kind, arity, per-entry `[key, value]` pair shape, duplicate values (the overlay requires unique values), the full heap invariant over keys under the direction-adjusted supplied order, and — with `options` — every key and value; guards run before the order is ever invoked.

### Parameters

#### payload

`unknown`

A statically typed serialized priority queue, or decoded `unknown` paired with runtime key and value validation.

#### keyOrder

[`Order`](/reference/knotkit/heap/type-aliases/order/)<`unknown`>

The base key order the queue was constructed under.

### Returns

[`DenseIntegerPriorityQueue`](/reference/knotkit/heap/interfaces/denseintegerpriorityqueue/) | [`PriorityQueue`](/reference/knotkit/heap/type-aliases/priorityqueue/)<`unknown`, `unknown`>

### Throws

When the payload is malformed or fails validation: not an object (`INVALID_SHAPE`), a missing or unsupported schema version (`UNSUPPORTED_SCHEMA_VERSION`), an unknown or cross-family `kind` (`UNKNOWN_KIND`), a missing or mistyped `entries` array (`MISSING_ENTRIES`), an unsafe or missing k-ary `arity` (`INVALID_ARITY`), an entry that is not a `[key, value]` pair (`INVALID_SHAPE`, naming the index), a key or value failing its guard (`INVALID_KEY`/`INVALID_VALUE`), a duplicate value (`DUPLICATE_VALUE`), or a parent-child key pair violating the heap invariant (`HEAP_INVARIANT_VIOLATION`, naming the offending entry index).
