Toolbox-XToolbox-X

Deep Parse Primitive Values

Recursively parses any input structure and converts stringified primitives into their actual JavaScript types.

deepParsePrimitives

Recursively parses an input (object, array, or primitive) and converts stringified numbers, booleans, null, and undefined to their proper JavaScript types throughout the structure.

Function Signature

function deepParsePrimitives<T = unknown>(input: unknown): T

Parameters

ParameterTypeDescription
inputunknownAny value: array, object, primitive, etc. to parse.

Returns

  • T: The parsed value with converted primitives.

Example Usage

playground.ts

Behavior Details

  • Deep Traversal: Recursively scans and transforms arrays, objects, and nested objects.
  • Conversion Rules:
    • "true"true
    • "false"false
    • "null"null
    • "undefined"undefined
    • Numeric string (e.g. "123") → 123
  • Already Typed Values: Leaves non-string primitives, functions, objects, and arrays untouched (except traversing inside them).

Aliases

This function can also be imported under the following name:

AliasImport Path
parsePrimitivesDeeptoolbox-x

  • parseJSON — Safely parses any JSON string with deep primitive parsing.
  • parseJsonToObject — Parses JSON strings strictly into objects, converting primitives.

Last updated: Sun, Jun 14, 2026 07:06:16AM (UTC)

On this page