Jump to content

Drill down into JSON structure


Recommended Posts

Hi! I want to create a workflow where I want to drill into a JSON Object returned from a script filter.

The object could look something like this:

// items being the result returned from the script filter
{
items: [
  {
    title: "Item 1",
    items: [
      {
        title: "Subitem 1.1"
        url: "/some/url"
      },
      {
        title: "Subitem 1.2"
        url: "/another/url"
      }
    ]
  },
  {
    title: "Item 2",
    items: [
      {
        title: "Subitem 2.1"
        url: "/some/url"
      },
      {
        title: "Subitem 2.2"
        url: "/another/url"
      }
    ]
  }
}


What I want to achieve is that after starting the workflow, the script filter fetches the initial list of items and that I then can action one of these items and "drill down" into the object structure.

So for this example, after invoking the workflow Alfred would show two results ("Item 1" and "Item 2") and after actioning the first item, it would show "Subitem 1.1" and "Subitem 1.2" which I could then action to open their URL in the browser.

Honestly, I'm quite lost ¯\_(ツ)_/¯ Any help would be greatly appreciated!

Link to comment

You can't do it that way, I'm afraid. Alfred only supports a flat list of items, not a tree.

 

You can recursively call the same Script Filter via External Triggers, but it's up to you to manage the position in the tree and return the appropriate list of items for that level.

 

Here's a workflow I wrote that can drill-down into your Safari bookmark folders. But it works by first flattening the tree into a list and using folderID to select a sub-tree.

 

If you want to keep your data as a tree structure, you might try passing a "dotted path", e.g. 1, 1.1, 1.2, back to your Script Filter and then extracting the relevant section.

Edited by deanishe
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...