In Firefox, "Organize Bookmarks," select "import and backup," "backup." Tell it
where to save the .json file. Stash it on a flash drive or other backup media.
On a fresh install, import that file.
As Roy points out, when you deal directly with any program's internal files,
there is always the chance that the format changes, and then you are out of
luck.
I follow a similar approach with Evolution: export from the old, import into the
new.