Skip to content

isJsonSequence

Checks whether a value is a string holding a valid JSON text sequence (RFC 7464, application/json-seq): records that each start with the record separator (U+001E) and hold one complete, strict JSON text.

It accepts exactly what @helpers4/json’s parseSequence accepts with its default options — every record must be valid, including the RFC’s check that a top-level number, true, false or null is followed by whitespace. An empty string is valid: it holds zero records.

Available since v3.1.3

import { isJsonSequence } from '@helpers4/guard';
// or, from the all-in-one package (same code, one install):
import { isJsonSequence } from 'helpers4/guard';
isJsonSequence(value: unknown): value is string
ParameterTypeDescription
valueunknownThe value to check

value is string — true if value is a string that parseSequence from @helpers4/json reads without error

Records framed by the record separator U+001E.

isJsonSequence('\u001E{"id":1}\n') // => true

RFC 7464 treats a top-level number without trailing whitespace as possibly truncated.

isJsonSequence('\u001E12') // => false

View source on GitHub