# deserializeSnapshotSetJson

## Call Signature

> **deserializeSnapshotSetJson**<`T`>(`serialized`): [`SnapshotSet`](/reference/knotkit/snapshot-set/interfaces/snapshotset/)<`T`>

Defined in: [packages/snapshot-set/src/serialization/json.ts:177](https://github.com/jkomyno/knotkit/blob/ef04dc6fd5182dca281abddf3e1dcb13118c15a4/packages/snapshot-set/src/serialization/json.ts#L177)

Rebuild a [SnapshotSet](/reference/knotkit/snapshot-set/interfaces/snapshotset/) from a [SerializedSnapshotSet](/reference/knotkit/snapshot-set/wire/interfaces/serializedsnapshotset/). O(k + m) time, where k is the number of registered values and m is the total number of toggle entries.

A round trip through `serializeSnapshotSetJson` and `deserializeSnapshotSetJson` preserves `kind`, `size`, `values()` order, and every `hasAt`/`valuesAt` answer for every id minted before serialization — including ids the caller held onto. A further `createSnapshot()` on the restored structure mints an id greater than every restored id, because the version counter is restored exactly, not recomputed by replaying `add`/`delete`.

Untyped input produces a `SnapshotSet<unknown>`. Pass a value type guard to validate decoded values and recover a narrower value type.

### Type Parameters

#### T

`T`

### Parameters

#### serialized

[`SerializedSnapshotSet`](/reference/knotkit/snapshot-set/wire/interfaces/serializedsnapshotset/)<`T`>

The structure to restore, either statically typed or decoded as `unknown`.

### Returns

[`SnapshotSet`](/reference/knotkit/snapshot-set/interfaces/snapshotset/)<`T`>

### Throws

When the serialized shape is malformed: a non-object payload, an unknown `kind`, a `values`/`history` length mismatch, a version or toggle-version entry that is not a non-negative safe integer, a history entry that is empty or not strictly increasing, a history or snapshot entry above `version`, a value’s first toggle version not strictly greater than the previous value’s, a duplicate value, or (with `options.isValue` supplied) a value that fails validation. Distinguish causes with `error.code`, one of SnapshotSetErrorCode.

## Call Signature

> **deserializeSnapshotSetJson**<`T`>(`serialized`, `options`): [`SnapshotSet`](/reference/knotkit/snapshot-set/interfaces/snapshotset/)<`T`>

Defined in: [packages/snapshot-set/src/serialization/json.ts:178](https://github.com/jkomyno/knotkit/blob/ef04dc6fd5182dca281abddf3e1dcb13118c15a4/packages/snapshot-set/src/serialization/json.ts#L178)

Rebuild a [SnapshotSet](/reference/knotkit/snapshot-set/interfaces/snapshotset/) from a [SerializedSnapshotSet](/reference/knotkit/snapshot-set/wire/interfaces/serializedsnapshotset/). O(k + m) time, where k is the number of registered values and m is the total number of toggle entries.

A round trip through `serializeSnapshotSetJson` and `deserializeSnapshotSetJson` preserves `kind`, `size`, `values()` order, and every `hasAt`/`valuesAt` answer for every id minted before serialization — including ids the caller held onto. A further `createSnapshot()` on the restored structure mints an id greater than every restored id, because the version counter is restored exactly, not recomputed by replaying `add`/`delete`.

Untyped input produces a `SnapshotSet<unknown>`. Pass a value type guard to validate decoded values and recover a narrower value type.

### Type Parameters

#### T

`T`

### Parameters

#### serialized

`unknown`

The structure to restore, either statically typed or decoded as `unknown`.

#### options

[`DeserializeSnapshotSetJsonOptions`](/reference/knotkit/snapshot-set/wire/interfaces/deserializesnapshotsetjsonoptions/)<`T`>

Runtime decoding options for untyped input.

### Returns

[`SnapshotSet`](/reference/knotkit/snapshot-set/interfaces/snapshotset/)<`T`>

### Throws

When the serialized shape is malformed: a non-object payload, an unknown `kind`, a `values`/`history` length mismatch, a version or toggle-version entry that is not a non-negative safe integer, a history entry that is empty or not strictly increasing, a history or snapshot entry above `version`, a value’s first toggle version not strictly greater than the previous value’s, a duplicate value, or (with `options.isValue` supplied) a value that fails validation. Distinguish causes with `error.code`, one of SnapshotSetErrorCode.

## Call Signature

> **deserializeSnapshotSetJson**(`serialized`): [`SnapshotSet`](/reference/knotkit/snapshot-set/interfaces/snapshotset/)<`unknown`>

Defined in: [packages/snapshot-set/src/serialization/json.ts:182](https://github.com/jkomyno/knotkit/blob/ef04dc6fd5182dca281abddf3e1dcb13118c15a4/packages/snapshot-set/src/serialization/json.ts#L182)

Rebuild a [SnapshotSet](/reference/knotkit/snapshot-set/interfaces/snapshotset/) from a [SerializedSnapshotSet](/reference/knotkit/snapshot-set/wire/interfaces/serializedsnapshotset/). O(k + m) time, where k is the number of registered values and m is the total number of toggle entries.

A round trip through `serializeSnapshotSetJson` and `deserializeSnapshotSetJson` preserves `kind`, `size`, `values()` order, and every `hasAt`/`valuesAt` answer for every id minted before serialization — including ids the caller held onto. A further `createSnapshot()` on the restored structure mints an id greater than every restored id, because the version counter is restored exactly, not recomputed by replaying `add`/`delete`.

Untyped input produces a `SnapshotSet<unknown>`. Pass a value type guard to validate decoded values and recover a narrower value type.

### Parameters

#### serialized

`unknown`

The structure to restore, either statically typed or decoded as `unknown`.

### Returns

[`SnapshotSet`](/reference/knotkit/snapshot-set/interfaces/snapshotset/)<`unknown`>

### Throws

When the serialized shape is malformed: a non-object payload, an unknown `kind`, a `values`/`history` length mismatch, a version or toggle-version entry that is not a non-negative safe integer, a history entry that is empty or not strictly increasing, a history or snapshot entry above `version`, a value’s first toggle version not strictly greater than the previous value’s, a duplicate value, or (with `options.isValue` supplied) a value that fails validation. Distinguish causes with `error.code`, one of SnapshotSetErrorCode.
