Jump to content
jprice

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!

Share this post


Link to post

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

Share this post


Link to post

Thank you! I've now essentially done the same thing (flattening the list). For my use case, this is sufficient. But I still think it would be a cool feature :)

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...