I usually do everything on my desktop computer, but recently I purchased a new laptop (the old one I didn't use at all due to some hardware issues). And now I need to synchronize my internet bookmarks between two devices. I use Mozilla Firefox as my primary web-browser most of the time. And most of the bookmarks I store there. I've read about Firefox Sync, but I don't feel like I want to use such services.

I decided to try to store my bookmarks in an org-mode document. This approach has one significant advantage for me: an org-mode document is a text document, so it can be easily put under the version control. And the version control enables me to synchronize information between devices and keeps the history of changes I've made.

First of all, I had to export my current bookmarks from Firefox to an org-mode document. Firefox allows us to export its bookmarks to a JSON file (Bookmarks -> Show All Bookmarks -> Import and Backup -> Backup...).

The structure of the JSON file is pretty obvious. It's a tree. Every node of the tree represents a bookmark or a bookmark folder. Also every node has several properties. The most important ones are:

With some properties omitted, the JSON looks like this:

{
    "title": "Bookmarks Toolbar",
    "type": "text/x-moz-place-container",
    "children": [
        {
            "title": "Search Engines",
            "type": "text/x-moz-place-container",
            "children": [
                {
                    "title": "Google",
                    "type": "text/x-moz-place",
                    "uri": "https://www.google.com/"
                },
                {
                    "title": "Yandex",
                    "type": "text/x-moz-place",
                    "uri": "http://www.yandex.com/"
                }
            ]
        },
        {
            "title": "Social Networks",
            "type": "text/x-moz-place-container",
            "children": [
                {
                    "title": "Twitter",
                    "type": "text/x-moz-place",
                    "uri": "https://twitter.com/"
                },
                {
                    "title": "Facebook",
                    "type": "text/x-moz-place",
                    "uri": "https://www.facebook.com/"
                }
            ]
        }
    ]
}

It's enough to write a simple program which parses the JSON, recursively traverses the tree and produces an org-mode document.

I wrote a simple python script which does this. It reads the JSON from stdin and writes the org-mode document to stdout. It translates folders to headlines and bookmarks to list items.

The script will convert the above JSON into the following org-mode document:

* Bookmarks Toolbar
** Search Engines
   - [[https://www.google.com/][Google]]
   - [[http://www.yandex.com/][Yandex]]
** Social Networks
   - [[https://twitter.com/][Twitter]]
   - [[https://www.facebook.com/][Facebook]]