# deserializeDisjointSetJson

## Call Signature

> **deserializeDisjointSetJson**<`T`>(`serialized`, `create`): [`GrowableDisjointSet`](/reference/knotkit/disjoint-set/interfaces/growabledisjointset/)<`T`>

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

Rebuild a disjoint set from a [SerializedDisjointSet](/reference/knotkit/disjoint-set/wire/type-aliases/serializeddisjointset/), restoring its recorded implementation unless a factory override is supplied. O(n \* alpha(n)) time.

Elements are added in serialized order, then every element is merged with the first element carrying its label. A round trip through `serializeDisjointSetJson` and `deserializeDisjointSetJson` preserves `size`, `setCount`, element order, and connectivity. It does not preserve which member is the representative.

Untyped input produces a [DeserializedDisjointSet](/reference/knotkit/disjoint-set/wire/type-aliases/deserializeddisjointset/) of `unknown` because the runtime `kind` may select either a generic layout or the numeric indexed layout. Pass an element type guard to validate generic decoded values.

### Type Parameters

#### T

`T`

### Parameters

#### serialized

[`SerializedGrowableDisjointSet`](/reference/knotkit/disjoint-set/wire/interfaces/serializedgrowabledisjointset/)<`T`>

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

#### create

[`GrowableDisjointSetFactory`](/reference/knotkit/disjoint-set/type-aliases/growabledisjointsetfactory/)

### Returns

[`GrowableDisjointSet`](/reference/knotkit/disjoint-set/interfaces/growabledisjointset/)<`T`>

### Throws

When the serialized shape or an element is invalid, or the two arrays have different lengths. Distinguish causes with `error.code`, one of DisjointSetErrorCode.

### Throws

When an element occurs twice.

## Call Signature

> **deserializeDisjointSetJson**<`T`>(`serialized`): [`GrowableDisjointSet`](/reference/knotkit/disjoint-set/interfaces/growabledisjointset/)<`T`>

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

Rebuild a disjoint set from a [SerializedDisjointSet](/reference/knotkit/disjoint-set/wire/type-aliases/serializeddisjointset/), restoring its recorded implementation unless a factory override is supplied. O(n \* alpha(n)) time.

Elements are added in serialized order, then every element is merged with the first element carrying its label. A round trip through `serializeDisjointSetJson` and `deserializeDisjointSetJson` preserves `size`, `setCount`, element order, and connectivity. It does not preserve which member is the representative.

Untyped input produces a [DeserializedDisjointSet](/reference/knotkit/disjoint-set/wire/type-aliases/deserializeddisjointset/) of `unknown` because the runtime `kind` may select either a generic layout or the numeric indexed layout. Pass an element type guard to validate generic decoded values.

### Type Parameters

#### T

`T`

### Parameters

#### serialized

[`SerializedGrowableDisjointSet`](/reference/knotkit/disjoint-set/wire/interfaces/serializedgrowabledisjointset/)<`T`>

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

### Returns

[`GrowableDisjointSet`](/reference/knotkit/disjoint-set/interfaces/growabledisjointset/)<`T`>

### Throws

When the serialized shape or an element is invalid, or the two arrays have different lengths. Distinguish causes with `error.code`, one of DisjointSetErrorCode.

### Throws

When an element occurs twice.

## Call Signature

> **deserializeDisjointSetJson**(`serialized`, `create`): [`GrowableDisjointSet`](/reference/knotkit/disjoint-set/interfaces/growabledisjointset/)<`number`>

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

Rebuild a disjoint set from a [SerializedDisjointSet](/reference/knotkit/disjoint-set/wire/type-aliases/serializeddisjointset/), restoring its recorded implementation unless a factory override is supplied. O(n \* alpha(n)) time.

Elements are added in serialized order, then every element is merged with the first element carrying its label. A round trip through `serializeDisjointSetJson` and `deserializeDisjointSetJson` preserves `size`, `setCount`, element order, and connectivity. It does not preserve which member is the representative.

Untyped input produces a [DeserializedDisjointSet](/reference/knotkit/disjoint-set/wire/type-aliases/deserializeddisjointset/) of `unknown` because the runtime `kind` may select either a generic layout or the numeric indexed layout. Pass an element type guard to validate generic decoded values.

### Parameters

#### serialized

[`SerializedIndexedDisjointSet`](/reference/knotkit/disjoint-set/wire/interfaces/serializedindexeddisjointset/)

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

#### create

[`GrowableDisjointSetFactory`](/reference/knotkit/disjoint-set/type-aliases/growabledisjointsetfactory/)

### Returns

[`GrowableDisjointSet`](/reference/knotkit/disjoint-set/interfaces/growabledisjointset/)<`number`>

### Throws

When the serialized shape or an element is invalid, or the two arrays have different lengths. Distinguish causes with `error.code`, one of DisjointSetErrorCode.

### Throws

When an element occurs twice.

## Call Signature

> **deserializeDisjointSetJson**(`serialized`): [`IndexedDisjointSet`](/reference/knotkit/disjoint-set/interfaces/indexeddisjointset/)

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

Rebuild a disjoint set from a [SerializedDisjointSet](/reference/knotkit/disjoint-set/wire/type-aliases/serializeddisjointset/), restoring its recorded implementation unless a factory override is supplied. O(n \* alpha(n)) time.

Elements are added in serialized order, then every element is merged with the first element carrying its label. A round trip through `serializeDisjointSetJson` and `deserializeDisjointSetJson` preserves `size`, `setCount`, element order, and connectivity. It does not preserve which member is the representative.

Untyped input produces a [DeserializedDisjointSet](/reference/knotkit/disjoint-set/wire/type-aliases/deserializeddisjointset/) of `unknown` because the runtime `kind` may select either a generic layout or the numeric indexed layout. Pass an element type guard to validate generic decoded values.

### Parameters

#### serialized

[`SerializedIndexedDisjointSet`](/reference/knotkit/disjoint-set/wire/interfaces/serializedindexeddisjointset/)

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

### Returns

[`IndexedDisjointSet`](/reference/knotkit/disjoint-set/interfaces/indexeddisjointset/)

### Throws

When the serialized shape or an element is invalid, or the two arrays have different lengths. Distinguish causes with `error.code`, one of DisjointSetErrorCode.

### Throws

When an element occurs twice.

## Call Signature

> **deserializeDisjointSetJson**<`T`>(`serialized`, `create`): [`GrowableDisjointSet`](/reference/knotkit/disjoint-set/interfaces/growabledisjointset/)<`number` | `T`>

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

Rebuild a disjoint set from a [SerializedDisjointSet](/reference/knotkit/disjoint-set/wire/type-aliases/serializeddisjointset/), restoring its recorded implementation unless a factory override is supplied. O(n \* alpha(n)) time.

Elements are added in serialized order, then every element is merged with the first element carrying its label. A round trip through `serializeDisjointSetJson` and `deserializeDisjointSetJson` preserves `size`, `setCount`, element order, and connectivity. It does not preserve which member is the representative.

Untyped input produces a [DeserializedDisjointSet](/reference/knotkit/disjoint-set/wire/type-aliases/deserializeddisjointset/) of `unknown` because the runtime `kind` may select either a generic layout or the numeric indexed layout. Pass an element type guard to validate generic decoded values.

### Type Parameters

#### T

`T`

### Parameters

#### serialized

[`SerializedDisjointSet`](/reference/knotkit/disjoint-set/wire/type-aliases/serializeddisjointset/)<`T`>

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

#### create

[`GrowableDisjointSetFactory`](/reference/knotkit/disjoint-set/type-aliases/growabledisjointsetfactory/)

### Returns

[`GrowableDisjointSet`](/reference/knotkit/disjoint-set/interfaces/growabledisjointset/)<`number` | `T`>

### Throws

When the serialized shape or an element is invalid, or the two arrays have different lengths. Distinguish causes with `error.code`, one of DisjointSetErrorCode.

### Throws

When an element occurs twice.

## Call Signature

> **deserializeDisjointSetJson**<`T`>(`serialized`): [`DeserializedDisjointSet`](/reference/knotkit/disjoint-set/wire/type-aliases/deserializeddisjointset/)<`T`>

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

Rebuild a disjoint set from a [SerializedDisjointSet](/reference/knotkit/disjoint-set/wire/type-aliases/serializeddisjointset/), restoring its recorded implementation unless a factory override is supplied. O(n \* alpha(n)) time.

Elements are added in serialized order, then every element is merged with the first element carrying its label. A round trip through `serializeDisjointSetJson` and `deserializeDisjointSetJson` preserves `size`, `setCount`, element order, and connectivity. It does not preserve which member is the representative.

Untyped input produces a [DeserializedDisjointSet](/reference/knotkit/disjoint-set/wire/type-aliases/deserializeddisjointset/) of `unknown` because the runtime `kind` may select either a generic layout or the numeric indexed layout. Pass an element type guard to validate generic decoded values.

### Type Parameters

#### T

`T`

### Parameters

#### serialized

[`SerializedDisjointSet`](/reference/knotkit/disjoint-set/wire/type-aliases/serializeddisjointset/)<`T`>

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

### Returns

[`DeserializedDisjointSet`](/reference/knotkit/disjoint-set/wire/type-aliases/deserializeddisjointset/)<`T`>

### Throws

When the serialized shape or an element is invalid, or the two arrays have different lengths. Distinguish causes with `error.code`, one of DisjointSetErrorCode.

### Throws

When an element occurs twice.

## Call Signature

> **deserializeDisjointSetJson**<`T`>(`serialized`, `options`): [`GrowableDisjointSet`](/reference/knotkit/disjoint-set/interfaces/growabledisjointset/)<`T`>

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

Rebuild a disjoint set from a [SerializedDisjointSet](/reference/knotkit/disjoint-set/wire/type-aliases/serializeddisjointset/), restoring its recorded implementation unless a factory override is supplied. O(n \* alpha(n)) time.

Elements are added in serialized order, then every element is merged with the first element carrying its label. A round trip through `serializeDisjointSetJson` and `deserializeDisjointSetJson` preserves `size`, `setCount`, element order, and connectivity. It does not preserve which member is the representative.

Untyped input produces a [DeserializedDisjointSet](/reference/knotkit/disjoint-set/wire/type-aliases/deserializeddisjointset/) of `unknown` because the runtime `kind` may select either a generic layout or the numeric indexed layout. Pass an element type guard to validate generic decoded values.

### Type Parameters

#### T

`T`

### Parameters

#### serialized

`unknown`

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

#### options

[`DeserializeDisjointSetJsonOptions`](/reference/knotkit/disjoint-set/wire/interfaces/deserializedisjointsetjsonoptions/)<`T`> & `object`

### Returns

[`GrowableDisjointSet`](/reference/knotkit/disjoint-set/interfaces/growabledisjointset/)<`T`>

### Throws

When the serialized shape or an element is invalid, or the two arrays have different lengths. Distinguish causes with `error.code`, one of DisjointSetErrorCode.

### Throws

When an element occurs twice.

## Call Signature

> **deserializeDisjointSetJson**<`T`>(`serialized`, `options`): [`DeserializedDisjointSet`](/reference/knotkit/disjoint-set/wire/type-aliases/deserializeddisjointset/)<`T`>

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

Rebuild a disjoint set from a [SerializedDisjointSet](/reference/knotkit/disjoint-set/wire/type-aliases/serializeddisjointset/), restoring its recorded implementation unless a factory override is supplied. O(n \* alpha(n)) time.

Elements are added in serialized order, then every element is merged with the first element carrying its label. A round trip through `serializeDisjointSetJson` and `deserializeDisjointSetJson` preserves `size`, `setCount`, element order, and connectivity. It does not preserve which member is the representative.

Untyped input produces a [DeserializedDisjointSet](/reference/knotkit/disjoint-set/wire/type-aliases/deserializeddisjointset/) of `unknown` because the runtime `kind` may select either a generic layout or the numeric indexed layout. Pass an element type guard to validate generic decoded values.

### Type Parameters

#### T

`T`

### Parameters

#### serialized

`unknown`

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

#### options

[`DeserializeDisjointSetJsonOptions`](/reference/knotkit/disjoint-set/wire/interfaces/deserializedisjointsetjsonoptions/)<`T`>

### Returns

[`DeserializedDisjointSet`](/reference/knotkit/disjoint-set/wire/type-aliases/deserializeddisjointset/)<`T`>

### Throws

When the serialized shape or an element is invalid, or the two arrays have different lengths. Distinguish causes with `error.code`, one of DisjointSetErrorCode.

### Throws

When an element occurs twice.

## Call Signature

> **deserializeDisjointSetJson**(`serialized`): [`DeserializedDisjointSet`](/reference/knotkit/disjoint-set/wire/type-aliases/deserializeddisjointset/)<`unknown`>

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

Rebuild a disjoint set from a [SerializedDisjointSet](/reference/knotkit/disjoint-set/wire/type-aliases/serializeddisjointset/), restoring its recorded implementation unless a factory override is supplied. O(n \* alpha(n)) time.

Elements are added in serialized order, then every element is merged with the first element carrying its label. A round trip through `serializeDisjointSetJson` and `deserializeDisjointSetJson` preserves `size`, `setCount`, element order, and connectivity. It does not preserve which member is the representative.

Untyped input produces a [DeserializedDisjointSet](/reference/knotkit/disjoint-set/wire/type-aliases/deserializeddisjointset/) of `unknown` because the runtime `kind` may select either a generic layout or the numeric indexed layout. Pass an element type guard to validate generic decoded values.

### Parameters

#### serialized

`unknown`

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

### Returns

[`DeserializedDisjointSet`](/reference/knotkit/disjoint-set/wire/type-aliases/deserializeddisjointset/)<`unknown`>

### Throws

When the serialized shape or an element is invalid, or the two arrays have different lengths. Distinguish causes with `error.code`, one of DisjointSetErrorCode.

### Throws

When an element occurs twice.
