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:

• type — determines the type of the node; the type text/x-moz-place-container means it's a bookmark folder; the type text/x-moz-place means it's a bookmark;
• children — a list of child nodes;
• uri — bookmarked URI; the nodes with the type text/x-moz-place-container usually don't have this property;
• title — a title of a bookmark folder or a bookmark.

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": [
{
"type": "text/x-moz-place",
},
{
"title": "Yandex",
"type": "text/x-moz-place",
"uri": "http://www.yandex.com/"
}
]
},
{
"title": "Social Networks",
"type": "text/x-moz-place-container",
"children": [
{
"type": "text/x-moz-place",
},
{
"type": "text/x-moz-place",
}
]
}
]
}


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