@umbraco-cms/backoffice
    Preparing search index...

    Function extractFirstJsonQueryContaining

    • Walks the JSON queries of a JSON-Path string, in order, and returns the properties of the first one matching the given find function.

      Parameters

      • path: string

        The JSON-Path string to search.

      • find: (props: Record<string, string>) => boolean

        A function to test each set of extracted properties.

      Returns Record<string, string> | undefined

      The properties of the first JSON query that matches the find function, or an empty object if none match.

      const path = `$.values[?(@.key == 'y')].value.contentData[?(@.alias == 'x')]`;
      const props = extractFirstJsonQueryContaining(path, (props) => props.alias !== undefined);
      console.log(props); // { alias: 'x' }