Skip to content

detectIndent

detectIndent(text): string | undefined

Defined in: stringify-json.ts:35

The indentation one level of nesting adds in a JSON document — the leading whitespace (spaces or a tab) of the first line after the first one, less any padding the root value’s own line starts with. undefined when there is none, e.g. a minified or single-line document.

Raw newlines can’t occur inside a JSON string, so any line that starts with whitespace is structural indentation.

string

string | undefined

import { detectIndent } from "@theholocron/json-utils";
detectIndent('{\n\t"a": 1\n}'); // "\t"
detectIndent('{"a":1}'); // undefined