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

    See coerceAnyJson for caveats regarding shallow type detection of AnyJson values from untyped sources.

    const obj = { foo: { bar: [{ a: 'b' }] } };
    const value = getAnyJson(obj, 'foo.bar[0]');
    // type of value -> AnyJson; value -> { a: 'b' }

    Parameters

    • from: Optional<AnyJson>

      The JSON value to query.

    • path: string

      The query path.

    Returns Optional<AnyJson>

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

    const obj = { foo: { bar: [{ a: 'b' }] } };
    const value = getAnyJson(obj, 'foo.bar[1]', { c: 'd' });
    // type of value -> AnyJson; value -> { c: 'd' }

    Parameters

    • from: Optional<AnyJson>

      The JSON value to query.

    • path: string

      The query path.

    • defaultValue: AnyJson

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

    Returns AnyJson