Search code examples
jsonsortinggoogle-chromejq

Output from Chrome Window / Tab Manager extension: Selecting a Window and sorting its Tabs with jq?


People,

Here is the head of an exported file:

{
  "tabfern": 42,
  "version": 1,
  "tree": [
    {
      "raw_title": "OpenAI",
      "tabs": [
        {
          "raw_title": "OpenAI",
          "raw_url": "https://openai.com/",
          "raw_favicon_url": "https://openai.com/favicon.ico"
        },
        {
          "raw_title": "Quickstart tutorial - OpenAI API",
          "raw_url": "https://platform.openai.com/docs/quickstart",
          "raw_favicon_url": "https://platform.openai.com/favicon.svg"
        },
etc . . 

and I want to use jq to select a particular window and sort the tabs within that window on the raw_url.

I have found if I use the "-S" switch I can sort the 3 lines within each Tab for ALL the tabs but I haven't found an example anywhere about how to choose a specific window and sort its tabs.

This exercise will only be necessary very infrequently for the case where the number of tabs has grown too large and trying to sort the tabs within the extension kills the browser . .

Any pointers appreciated!

Thanks, Phil.


Solution

  • You're looking for something like this:

    jq --arg window 'OpenAI' '(.tree[] | select(.raw_title == $window)) .tabs |= sort_by(.raw_url)'