Function isJSONPropertyPath

  • Determines whether a value is a JSONPropertyPath.

    A JSON property path is either:

    • A non-empty dotted string.
    • A non-empty, dense array containing only strings and finite numbers.

    Symbol segments are rejected because symbols cannot be represented by JSON. Non-finite numbers are also rejected because JSON.stringify converts NaN, Infinity, and -Infinity to null. Sparse arrays are rejected because missing elements are likewise serialized as null.

    Numeric values do not need to be integers or valid array indexes. This function validates lossless JSON representation only; array-index constraints remain dependent on the value traversed by a path-aware operation.

    -0 is accepted because JSON normalizes it to 0, which is equivalent under the package's property-key comparison semantics.

    Parameters

    • value: unknown

      Value to evaluate.

    Returns value is JSONPropertyPath

    Whether the value is a non-empty property path that can be represented losslessly through ordinary JSON serialization.

    isJSONPropertyPath('actor.system.hp');       // true
    isJSONPropertyPath(['actors', 0, 'name']); // true
    isJSONPropertyPath(['literal.period']); // true

    isJSONPropertyPath([Symbol('metadata')]); // false
    isJSONPropertyPath(['actors', NaN]); // false
    isJSONPropertyPath(new Array(1)); // false