How to parse Firefox manual JSON bookmarks backup using jq? -


i've created own json bookmark backup according page : http://kb.mozillazine.org/backing_up_and_restoring_bookmarks_-_firefox#creating_bookmark_backups

i won't post json bookmark backup file here (it's big), can create own file , have @ entire file.

then testing tried uri of bookmarks (later extract other datas too) didn't work

jq -r '.[] | .uri' bookmarks-2017-09-13.json  jq: error (at bookmarks-2017-09-13.json:1): cannot index string string "uri"  jq -r '.uri' bookmarks-2017-09-13.json  null 

version of firefox : firefox 55.0.2 (64 bits) ubuntu 16.04 lts

version of jq : jq-1.5-1-a5b5cbe

regards

here solution using tostream.

    tostream                       # read [[path],value] , [[path]] stream   | select(length==2) [$p,$v]   # put [path] in $p , value in $v   | select($p[-1] == "uri")        # keep paths ending in "uri"   | $v                             # emit value 

if above filter in filter.jq , data.json contains following sample bookmark data:

{   "guid": "root________",   "title": "",   "index": 0,   "dateadded": 1000000000000000,   "lastmodified": 1000000000000000,   "id": 1,   "type": "text/x-moz-place-container",   "root": "placesroot",   "children": [     {       "guid": "menu________",       "title": "bookmarks menu",       "index": 0,       "dateadded": 1000000000000000,       "lastmodified": 1000000000000000,       "id": 2,       "type": "text/x-moz-place-container",       "root": "bookmarksmenufolder",       "children": [         {           "guid": "yge5sog8iwid",           "title": "stack overflow",           "index": 0,           "dateadded": 1000000000000000,           "lastmodified": 1000000000000000,           "id": 3,           "iconuri": "https://cdn.sstatic.net/sites/stackoverflow/img/favicon.ico?v=4f32ecc8f43d",           "annos": [             {               "name": "bookmarkproperties/description",               "flags": 0,               "expires": 4,               "value": "stack overflow largest, trusted online community developers learn, share​ ​their programming ​knowledge, , build careers."             }           ],           "type": "text/x-moz-place",           "uri": "https://stackoverflow.com/"         }       ]     } 

then command

$ jq -mr -f filter.jq data.json 

produces

https://stackoverflow.com/ 

Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -