• Given a deep-search query path, returns an object property or array value from an AnyJson as a JsonArray, or undefined if a value was not found or was not type-compatible.

    const obj = { foo: { bar: [1, 2, 3] } };
    const value = getJsonArray(obj, 'foo.bar');
    // type of value -> JsonArray; value -> [1, 2, 3]

    Parameters

    • from: Optional<AnyJson>

      The JSON value to query.

    • path: string

      The query path.

    Returns Nullable<JsonArray>

  • Given a deep-search query path, returns an object property or array value from an AnyJson as a JsonArray, or the given default if a value was not found or was not type-compatible.

    const obj = { foo: { bar: [1, 2, 3] } };
    const value = getJsonArray(obj, 'foo.baz', [4, 5, 6]);
    // type of value -> JsonArray; value -> [4, 5, 6]

    Parameters

    • from: Optional<AnyJson>

      The JSON value to query.

    • path: string

      The query path.

    • defaultValue: JsonArray

      The default to return if the query result was not defined.

    Returns JsonArray