Results 1 to 28 of 28

Thread: Firefox - Find and Delete Bookmarks

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2017
    Posts
    863

    Firefox - Find and Delete Bookmarks

    I've got a boat load of bookmarks in Firefox.
    I'm sure a lot are invalid as web pages have changed or no longer exist.
    What I would like to do, is load Firefox's bookmark file into VB,
    extract the url from each bookmark within that file, and
    then attempt to access the web page using the bookmark web link.

    If the web page does Not exist, then delete the bookmark from
    Firefox's bookmark file.

    I can handle the call to the web page via VB to check its validity, but never coded against Firefox.

    Does anyone know whether the Firefox bookmark file is in a propriety or open format and where I can obtain that format?

  2. #2

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2017
    Posts
    863
    Last edited by vb6forever; Dec 10th, 2017 at 09:12 PM.

  3. #3
    PowerPoster
    Join Date
    Aug 2010
    Location
    Canada
    Posts
    2,451

    Re: Firefox - Find and Delete Bookmarks

    Is this a one-off need? If so, you can export your Firefox bookmarks to an HTML file, parse that for URLs to test, then build another HTML file that includes just the "valid" bookmarks and import that back into Firefox.

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2017
    Posts
    863

    Re: Firefox - Find and Delete Bookmarks

    jpbro: Thanks for responding.

    Is this a one-off need?
    Yes, that's how I see -or- maybe rare need.
    What you propose is comparable to my original post.
    Per original post, unknown -- to me -- the format of Firefox bookmark file.
    Using version 54.

    ==============
    Per suggestion.
    Exported bookmark file to an HTML file from Firefox but as indicated format is unknown. At top say "DO NOT EDIT" but looks like using compresson of some sort.
    Last edited by vb6forever; Dec 10th, 2017 at 10:41 PM.

  5. #5
    PowerPoster
    Join Date
    Aug 2010
    Location
    Canada
    Posts
    2,451

    Re: Firefox - Find and Delete Bookmarks

    Try this:

    • [#] In Firefox, press Ctrl+Shift+B. The Library window appears.
      [#] Click the Import and Backup menu, then click Export bookmarks to HTML.
      [#] Save the bookmarks.html file.


    If you open that file in a text editor, you'll see a bunch of <DT> tags containing <A> tags. Those <A> tags contain your URLS. If they start with something other than http:, https:, or ftp: you should probably skip them (for example place: urls are for internal use by Firefox to point to a bookmark folder I think).

    As you test each URL, you will remove the entire <DT> and preceding <DD> nodes to remove a failed entry.

  6. #6
    PowerPoster
    Join Date
    Aug 2010
    Location
    Canada
    Posts
    2,451

    Re: Firefox - Find and Delete Bookmarks

    Looking at that HTML file produced by the latest Firefox though, it appears that none of the <DT> or <DD> tags have a corresponding closing </DT> or </DD>...This is probably a bug, and it will make parsing a bit more difficult if you are using a library that expects closing tags.

  7. #7
    PowerPoster
    Join Date
    Aug 2010
    Location
    Canada
    Posts
    2,451

    Re: Firefox - Find and Delete Bookmarks

    Looked into it a bit further - I guess the closing </DT> and </DD> tags aren't part of the doctype spec for the HTML file produced as described above. The doctype is Netscape Bookmark File Format and is described in a bit more detail here: https://msdn.microsoft.com/en-us/lib...(v=vs.85).aspx

  8. #8
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Firefox - Find and Delete Bookmarks

    If the web page does Not exist, then delete the bookmark from
    Firefox's bookmark file.
    depending on the operating system and webbrowser, some links maybe invalid in your vb6 test, but still accessible to firefox
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  9. #9

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2017
    Posts
    863

    Re: Firefox - Find and Delete Bookmarks

    jpbro and westconn1 thanks for additional info.

    Haven't tried westconn1 suggestion, but interestingly with original attempt (#4)
    notepad shows the compression format, but when file contents shows in Windows Explorer on right side, it shows readable textual in a tree format BUT "no" links show.
    So there obviously is a library (maybe Firefox's own) on my system that Windows is using.

  10. #10
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,253

    Re: Firefox - Find and Delete Bookmarks

    Taking up jpbros hint about "In Firefox, press Ctrl+Shift+B. The Library window appears." -
    I'd choose the Top-Option [Save...] - which exports to a *.json-File.

    This *.json File-Content can be:
    - easily parsed with VB6 (into a Colleciton-Container)
    - then (recursively) enumerated
    - and if the child-node-type is right ("typeCode":1 or alternatively "type":"text/x-moz-place")
    - then you could check the "uri" Field of that node ( "uri":"http://...." )
    - and if that uri-field matches certain conditions, you will remove the whole child-node from the Collection(-tree)

    After you are through with that recursive Enumeration and Filtering of the JSON-Object,
    you simply write its serialized JSON-content back out as a file like e.g. "myChangedPlaces.json" -
    and then re-import from it.

    There is online-JSON-formatters and -viewers (as e.g. https://jsonformatter.curiousconcept.com/),
    which allow to paste JSON-string-content into a box - and then show the parsed JSON in a nice tree
    (in case you want to look at the exported structure comfortably, or to get an idea about the field-names in a node).

    Olaf

  11. #11

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2017
    Posts
    863

    Re: Firefox - Find and Delete Bookmarks

    Olaf:

    Thanks for the suggestion and building on jpbro's one-off idea.
    Re:
    This *.json File-Content can be:
    - easily parsed with VB6 (into a Colleciton-Container)
    - then (recursively) enumerated
    Hopefully -- Never messed with Json so another learning curve to climb.

  12. #12
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,253

    Re: Firefox - Find and Delete Bookmarks

    Quote Originally Posted by vb6forever View Post
    Hopefully -- Never messed with Json so another learning curve to climb.
    FWIW, JSON (as a hierarchical Text-Format) is definitely way easier than e.g. XML.

    And with e.g. the built-in stuff in the RC5, the whole taks becomes quite easy to understand (IMO):

    Here's, what I've just successfully tested with a freshly exported JSON-Bookmarklist
    (using recent FireFox 57.02 - which on my machine by default places the bookmark-backup-files in the Users Desktop-Folder):

    Code:
    Option Explicit
    
    Private PathToJSONFiles As String
    
    Private Sub Form_Load()
      PathToJSONFiles = New_c.FSO.GetSpecialFolder(CSIDL_DESKTOPDIRECTORY) 'FireFox saves per default into the Desktop-Directory
      
      Dim DL As cDirList
      Set DL = New_c.FSO.GetDirList(PathToJSONFiles, dlSortByLastWriteTime, "bookmarks*.json")
       If DL.FilesCount = 0 Then MsgBox "No *.json-Files found in: " & DL.Path: Exit Sub
    
      Dim JSONUtf8Bytes() As Byte, JSONRoot As cCollection
          JSONUtf8Bytes = New_c.FSO.ReadByteContent(DL.Path & DL.FileName(DL.FilesCount - 1)) '<- the most recent one is at the end of the DL-FileList
      Set JSONRoot = New_c.JSONDecodeToCollectionUTF8(JSONUtf8Bytes)
      
      Dim FilteredNodes As cCollection
      Set FilteredNodes = New_c.Collection
      If JSONRoot.Exists("children") Then ParseJSONFile JSONRoot("children"), FilteredNodes
      Debug.Print "FilteredNodes.Count:"; FilteredNodes.Count
      Debug.Print "filtered (new) JSON"; vbLf; JSONRoot.SerializeToJSONString
      New_c.Clipboard.SetText JSONRoot.SerializeToJSONString
    End Sub
    
    Private Sub ParseJSONFile(oJSON As cCollection, Optional FilteredNodes As cCollection, Optional ByVal Indent&)
      Dim i As Long, CN As cCollection
      For i = oJSON.Count - 1 To 0 Step -1
        Set CN = oJSON.ItemByIndex(i) 'get the current ChildNode into a separate JsonCol-Object
        
        If CN("typeCode") = 2 Then 'a Place-Container, let's enumerate deeper
          Debug.Print Space(Indent) & "[" & CN("title") & "] " & CN("type")
          If CN.Exists("children") Then ParseJSONFile CN("children"), FilteredNodes, Indent + 4
        ElseIf CN("typeCode") = 1 Then 'a Place
          Debug.Print Space(Indent) & "Place->title: " & CN("title")
          Debug.Print Space(Indent + 5) & "->uri:   " & CN("uri")
          If UriExcludeFilterMatch(CN("uri")) Then
            oJSON.RemoveByIndex i
            If Not FilteredNodes Is Nothing Then FilteredNodes.Add CN
          End If
        End If
      Next
    End Sub
    
    Private Function UriExcludeFilterMatch(uri As String) As Boolean
      UriExcludeFilterMatch = True
    End Function
    Now it's up to you, to "plow your way" through the above snippet...

    HTH

    Olaf

  13. #13

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2017
    Posts
    863

    Re: Firefox - Find and Delete Bookmarks

    Olaf:
    Thanks a bunch.
    Didn't expect you to do my work.
    Will see what I can do with it.

  14. #14

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2017
    Posts
    863

    Re: Firefox - Find and Delete Bookmarks

    First Issue (may be Firefox 54 versus 57) is:

    Will ONLY allow export to html NOT json.

  15. #15
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,253

    Re: Firefox - Find and Delete Bookmarks

    Quote Originally Posted by vb6forever View Post
    First Issue (may be Firefox 54 versus 57) is:

    Will ONLY allow export to html NOT json.
    Is there no Backup... (Restore) Menu-entries?

    Olaf

  16. #16

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2017
    Posts
    863

    Re: Firefox - Find and Delete Bookmarks

    Yes: There is both a backup and restore.

    Backup shows as a json file and YES default is Desktop.
    Sorry missed your reference to it in post #12. Since I lost one eye to choroidal melanoma last year been struggling a bit. Can't recommend enough dialated eye exam by opthomologist yearly at least to catch it early as possible.

    Retore just lists a number of dates -- which I assume are previously created bookmark files.
    Don't know where the restore files came from as I never manually backed up as I recall.
    Will overwrite current backup.
    Last edited by vb6forever; Dec 12th, 2017 at 01:25 PM.

  17. #17

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2017
    Posts
    863

    Re: Firefox - Find and Delete Bookmarks

    --------------------------
    Olaf:
    I had the same issues with RC5 as outlined by OldClock in
    the thread: "Cannot change array element in collection"
    So didn't want you to think I "dis" you for your above effort on my behalf
    -------------------------------------------------------------------

    Have gotten deeper into this than what I expected.
    Found a VB6 JSON parser with source code and have spent last several days understanding it. The Sample files appear to parse correctly.
    However, when trying to parse the Firefox bookmark it Errors on the
    sequence
    Code:
      [{
    which should be an array of objects based on my reading of the JSON standard.

    Attached is a zip file which contains
    1) A picture of the key portion of the bookmark file in a hex editor
    (loaded both JPG and MHT formats)
    2) The debug file output dated 20171222 945PM.

    ------------
    Question
    ----------
    1) Is the JSON sequence of
    Code:
      [{
    a valid construct -or- is Firefox doing something goofy using this sequence?
    If correct, then the parser needs some work.
    Attached Files Attached Files
    Last edited by vb6forever; Dec 22nd, 2017 at 09:57 PM.

  18. #18
    PowerPoster
    Join Date
    Aug 2010
    Location
    Canada
    Posts
    2,451

    Re: Firefox - Find and Delete Bookmarks

    I just tried exporting my Firefox bookmarks to a JSON file, then reading them into an RC5 cCollection object via the JSONDecodeToCollection method, and then tried modifying an item by index, and I encountered no errors.

    Perhaps you could post your code and the JSON file you are working with?

  19. #19

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2017
    Posts
    863

    Re: Firefox - Find and Delete Bookmarks

    jpbro (thanks for responding):

    Planned to post entire project when finished - or - before if can't solve this issue.
    However, right now, wanted to see if I could resolve issue myself and learn something at the same time.

    Just needed a little feedback - but looking at my error file -- didn't notice before -- that Firefox is
    using the same construct "[{" prior to error. So whether the nesting is to deep for the parser or something
    else, will spend a bit checking it out.

  20. #20

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2017
    Posts
    863

    Re: Firefox - Find and Delete Bookmarks

    Problem Identified in JSON parsing program is parser wants to assign a "duplicate key" to the Dictionary.
    Since Firefox bookmarks use a lot of the same field names (e.g. dateAdded, dateModified, etc.) and the
    parser assigns these names as a Key, when the Key already exists, the program errors.

    Several questions come to mind:
    1) Should a unique key be generated -- (appending the Item value to the Key will not work as for example dates may duplicate)
    and if so what is the best way?
    2) Should a dictionary or collection even be used as output for the parser?

  21. #21
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,253

    Re: Firefox - Find and Delete Bookmarks

    Quote Originally Posted by vb6forever View Post
    Several questions come to mind:
    - ... Is the JSON sequence of {[ ... a valid construct
    - ... Should a unique key be generated
    JSON is well-documented (if you google a bit) - and the answer to each of your above questions is: Yes.

    Quote Originally Posted by vb6forever View Post
    2) Should a dictionary or collection even be used as output for the parser?
    A Collection-Type (which allows access per Key for JSON-Object-Nodes and access per Index for JSON-Array-Nodes)
    is an obvious choice (the Optionality of the Key-Param, whilst adding an Item to a JSON-Array-Node coming in handy I guess).

    What I don't really understand is, why you are trying to write your own JSON-parser (diving directly into "coding-mode") -
    without informing yourself about the well-documented JSON-format first (what is allowed and what not).

    That suggests to me (without meaning to be offensive), that you are the kind of developer,
    who *should* (re)use existing libraries - instead of "trying to re-invent the wheel in a less efficient fashion".

    Millions of JavaScript-developers do just that, by using a simple (built into all modern Browsers) library call:
    Code:
    var myJsonObj;
        myJsonObj = JSON.parse(someJSONString);
    And the VB-equivalent could be (when using the RC5-cCollection):
    Code:
    Dim myJsonObj As cCollection
    Set myJsonObj = New_c.JSONDecodeToCollection(someJSONString)
    Accessing the Properties of (or nested Enumerations on) these Collection-Objects is then quite easy in both cases,
    leaving all the little details of the JSON-format out of the loop (which involve besides the parsing also: proper Handling of Unicode- or Escaping).

    As I see it, a complete solution to your concrete problem: "Firefox - Find and Delete Bookmarks"
    was given to you (in about 30 lines of code or so) already in post #12.

    Why not just use it (after some small adaptions, putting a GUI around it) "as is"
    (on your private machine for your private purposes)?

    Olaf

  22. #22

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2017
    Posts
    863

    Re: Firefox - Find and Delete Bookmarks

    Olaf:

    Had a great response BUT *%^&*$ forum timed me out and consequently lost.
    Anything you can do about the forum timing out would be GREAT.

    That said:
    1) the first thing I did was download the JSON spec.

    http://ecma-international.org/public...T/ECMA-404.pdf

    2) the second was make a decision regarding the amount of effort to learn RC5 versus
    seeing if I could locate a VB JSON parser, which I found.
    3) In both cases -- RC5 or VB parser -- I had to climb a learning curve.
    Going the VB parser route I learned a lot about JSON, parsers
    -- BUT -- sadly I could never get the parser to do Firefox JSON.


    Was going to upload parser, but 9MB and upload was taking forever. Holiday traffic or NET Neutral at work?

    Followed the links to github from this reference.:
    https://www.codeproject.com/articles...ed-performance

    and here for Github Source:
    https://github.com/samgerene/VBJSOND...r/VB6%20Source

    For Firefox (download your Firefox bookmarks as a JSON file and put in same directory
    as Source. Put a Command Button on frmMain and then copy the following code to frmMain
    Could never get the parseObject Dictionary when assigned to Collection to return other than Empty.

    Code:
    Private Sub Command1_Click()
    'Parse Firefox JSON file
    
        '-------------------------------
    
        Dim sw As New StopWatch
        Dim elapsedtime As Long
        Dim filename As String
        Dim filecontents As String
        Dim resultstring As String
        Dim numberofruns As Integer
        Dim i As Integer
        Dim totaltime As Long
        Dim arraytime As Long
        
       '>> dwAdd
         Dim j As Integer
        Dim sTypes As String
        Dim key As Variant
        Dim vkeyName As Variant
        Dim strKeyName As String
        Dim vItem As Variant
        Dim vColItem As Variant
        Dim vCNItem As Variant
        '>> dwAddEnd
        
        'Objects
        Dim vObject As Variant
        Dim oDict As Dictionary
        Dim oCol As Collection
        Dim deserializer As cJSONDeserializer    '<<Class
        Dim CN As Collection
     
        '************
        'STARTUP
        '************
        numberofruns = 5
        filename = Me.TextFilePath.Text
        filecontents = FileText(filename)
        
        Screen.MousePointer = vbHourglass
        
        '************
        'MAIN
        '************
        
        '-------------------------------------------------------------------------------------
        'Parse with Original JASON parser
        'Uses Jason.bas
        '-------------------------------------------------------------------------------------
        If Me.CheckJson.Value = vbChecked Then
    
            totaltime = 0
    
            For i = 1 To numberofruns
                sw.StartTimer
    
                Set vObject = JSON.parse(filecontents)
    
                elapsedtime = sw.EndTimer
                totaltime = totaltime + elapsedtime
    
                resultstring = Now & vbCrLf & _
                                "Parsing time: " & elapsedtime & " [micro sec]" & vbCrLf & _
                                "vObject.Count: " & vObject.Count
    
                Me.txtJSON.AppendText resultstring & vbCrLf, True, True
    
                DoEvents
            Next i
    
            Me.txtJSON.AppendText vbCrLf & "average time: " & Round((totaltime / numberofruns), 2) & " [micro sec]", True, True
    
          'dw Test 20171214
           '------------------------------------------------------
           'File Contains More Than One vObject
           'Handle Each One Separately
           '------------------------------------------------------
           For i = 0 To vObject.Count - 1         '<<There are 9 dictionary objects  is vObject.Count base 0 or base 1 ??
     
    Debug.Print '>>>>>>>>>>>   i = " & CStr(i)
    'If i > 0 Then Stop
     
                Set oDict = vObject               'More than one dictionary (??? ) so get each one.
    
                
                'Enum dictionary to make sure Key exist
                For Each key In oDict.keys
                
                    '---------------------
                    'Get Each  Key
                    '---------------------
                    vkeyName = key
                    strKeyName = CStr(key)
    '                Debug.Print "Key:", strKeyName
    
                    '-------------------------------------------------------------------
                    ' Get Each Key Type
                    'Types id so far are:  String, Decimal, Boolean, Collection, ?????
                    '-------------------------------------------------------------------
     '               sTypes = sTypes & IIf(sTypes <> "", ",", "") & TypeName(oDict(key))       '<< Lists all types in comma delimited  string
                     sTypes = TypeName(oDict(key))
     '                Debug.Print "Key:", strKeyName, "KeyType:", sTypes
    
                    '-------------------------------------------------------------------
                    ' Get Item by Key Type for Each Key
                    '-------------------------------------------------------------------
                    On Error Resume Next
                    Select Case sTypes
                        Case "String"
                            vItem = oDict.Item(strKeyName)
                            
                            If Not IsEmpty(vItem) Then
                                Debug.Print "String", strKeyName & "  :", CStr(vItem)
                            End If
    
                        Case "Decimal"
                             vItem = oDict.Item(strKeyName)
                             
                             If Not IsEmpty(vItem) Then
                                Debug.Print "Decimal", strKeyName & "  :", CStr(vItem)
                            End If
    
                        Case "Collection"
                        
    ' If strKeyName = "children" Then Stop
                              'Look for Node of Interest.   Exists maybe a better construct than Alternative
                             If oDict.Exists("children") Then           '<< Alternative code:: If strKeyName = "children" Then
                             
                                '================
                                ' 'Parse the Collection
                                
    '                            '>>Per  Olaf  (see his code at Proc: ParseJSONFile
    '                            Dim FilteredNodes As cCollection'
    '                            Set FilteredNodes = New_c.Collection
    '                            Call ParseJSONFile(oDict.Item("children"))
                                 '>>Test 3 End
                                
                                '================
                                  'Assign this Dictionary Key to a Collection
    '                                Dim CN As New Collection
                                  Set CN = oDict.Item("children")   'ALSO TRIED:  Set CN = oDict("children")
                                  For j = 1 To CN.Count
                                  
                                      vCNItem = CN.Item(j)
                                      
                                      If Not IsEmpty(vCNItem) Then
                                          Debug.Print "Child.Item:  " & CStr(vCNItem)
                                      End If
    
                                  Next
      
                             End If       'Exists children
                             
                        Case "Boolean"
                             vItem = oDict.Item(strKeyName)
                             
                             If Not IsEmpty(vItem) Then
                                Debug.Print "Boolean", strKeyName & "  :", CStr(vItem)
                            End If
                             
                             
                         Case "Null"
                            vItem = oDict.Item(strKeyName)
    
                        Case "Array"
     
                        Case "Object"
                        
                              'From cmdRun
                             'Look for Node of Interest.   Exists maybe a better construct than Alternative
                             If oDict.Exists("children") Then           '<< Alternative code:: If strKeyName = "children" Then
            
                                     For Each vItem In oDict.Item("children")
                                         vColItem = vItem
                                         Debug.Print vColItem
                            '            Me.txtVBJSONDeserializer.AppendText CStr(vColItem) & vbCrLf, True, True
                                    Next
                             
                                'get the current ChildNode into a separate JsonCol-Object
             '                   Set oCol = vObject
             '                   Set oCol = oDict.Item(strKeyName)
              
                                 Stop
                             End If       'Exists children
                             
                        End Select
                
                Next key
                
           Next
           
        End If
    
        '-------------------------------------------------------------------------------------
        'Parse Using Improved VBSerializer Parser
        'User has option to test either Module or Class Implementation
        '-------------------------------------------------------------------------------------
        If Me.CheckVBJSONDeserializer.Value = vbChecked Then
            
            totaltime = 0
            
            For i = 1 To numberofruns
                sw.StartTimer
                
                If Me.OptionMod Then
                    'Use Module
                    Set vObject = VBJSONDeserializer.parse(filecontents)     '<<Returns Object
                    Debug.Print VBJSONDeserializer.GetParserErrors
                Else
                      'Use Class
                    Set deserializer = New cJSONDeserializer
                    Set vObject = deserializer.parse(filecontents)
                    Set deserializer = Nothing
                    arraytime = 0
                End If
                
                elapsedtime = sw.EndTimer
                totaltime = totaltime + elapsedtime
                
                resultstring = Now & vbCrLf & _
                                "Parsing time: " & elapsedtime & " [micro sec]" & vbCrLf & _
                                "vObject.Count: " & vObject.Count
                
                Me.txtVBJSONDeserializer.AppendText resultstring & vbCrLf, True, True
                
                DoEvents
            Next i
            
            Me.txtVBJSONDeserializer.AppendText vbCrLf & "average time: " & Round((totaltime / numberofruns), 2) & " [micro sec]" & vbCrLf, True, True
            
            '-------------------------------------------------------------------------------------
            'Enumerate the Dictionary and Show the Parsed Contents by Element (tag)
            '------------------------------------------------------------------------------------
            If Me.CheckShowNames.Value = vbChecked Then
            
                   '----------- Test
    
        '
        '        Dim oDict As Dictionary
        '        Set oDict = VBJSONDeserializer.parse(filecontents)
        '
                'Enum dictionary to make sure Key exist
    '            For Each key In oDict.keys
    '                  vkeyName = key
    '                  strKeyName = CStr(key)
    '            Next key
    ''
    '            'Enum dictionary to make sure Collection Items exist for this Key
    '            For Each key In oDict.keys
    '
    '                  vKeyName = key
    '                  Debug.Print vKeyName
    '
    '                  For Each vItem In oDict(vKeyName)
    '                       vColITem = vItem
    '                       Debug.Print vColITem
    '                  Next
    '
    '            Next key
                    '----------- Test End
                    
    '
     
           '------------------------------------------------------
           'File Contains More Than One vObject
           'Handle Each One Separately
           '------------------------------------------------------
           For i = 0 To vObject.Count - 1         '<<There are 9 dictionary objects  is vObject.Count base 0 or base 1 ??
     
    Debug.Print '>>>>>>>>>>>   i = " & CStr(i)
    If i > 0 Then Stop
     
                Set oDict = vObject               'More than one dictionary (??? ) so get each one.
    
                
                'Enum dictionary to make sure Key exist
                For Each key In oDict.keys
                
                    '---------------------
                    'Get Each  Key
                    '---------------------
                    vkeyName = key
                    strKeyName = CStr(key)
    '                Debug.Print "Key:", strKeyName
    
                    '-------------------------------------------------------------------
                    ' Get Each Key Type
                    'Types id so far are:  String, Decimal, Boolean, Collection, ?????
                    '-------------------------------------------------------------------
     '               sTypes = sTypes & IIf(sTypes <> "", ",", "") & TypeName(oDict(key))       '<< Lists all types in comma delimited  string
                     sTypes = TypeName(oDict(key))
     '                Debug.Print "Key:", strKeyName, "KeyType:", sTypes
    
                    '-------------------------------------------------------------------
                    ' Get Item by Key Type for Each Key
                    '-------------------------------------------------------------------
                    On Error Resume Next
                    Select Case sTypes
                        Case "String"
                            vItem = oDict.Item(strKeyName)
                            
                            If Not IsEmpty(vItem) Then
                                Debug.Print "String", strKeyName & "  :", CStr(vItem)
                            End If
    
                        Case "Decimal"
                             vItem = oDict.Item(strKeyName)
                             
                             If Not IsEmpty(vItem) Then
                                Debug.Print "Decimal", strKeyName & "  :", CStr(vItem)
                            End If
    
                        Case "Collection"
                        
    ' If strKeyName = "children" Then Stop
                              'Look for Node of Interest.   Exists maybe a better construct than Alternative
                             If oDict.Exists("children") Then           '<< Alternative code:: If strKeyName = "children" Then
                             
                                '================
                                ' 'Parse the Collection
                                '================
                             
    '                                '>>Test 1 (works to some degree
    '                                'Assign this Dictionary Key to a Collection
    '                                Dim CN As New Collection
                                    Set CN = oDict("children")
    '                                Dim vCNItem As Variant
                                    
                                    For j = 0 To CN.Count - 1
                                    
                                        vItem = CN.Item(j)
                                        
                                        If Not IsEmpty(vItem) Then
                                            Debug.Print "Child.Item:  " & CStr(vItem)
                                        End If
      
                                    Next
         
    '                                vItem = CN.Item("title")
    '                                Debug.Print "title", CStr(vItem)
    '                                vItem = CN("uni")
    '                                Debug.Print "uni", CStr(vItem)
                                    
    '               Debug.Print Space(5) & "Place->title: " & CN("title") & CN.Item("title")
    '                Debug.Print Space(10) & "->uri:   " & CN("uri") & CN.Item("uni")
    '
    '                                 'Look at the Collection Items for this Key
    '                                 Set CN = oDict.Item("children")
    '                                 For Each vItem In CN.Item("children")
    '
    '                                    '  If Not vItem Is Nothing Then Stop       'says Empty
    '                                     vColItem = vItem
    '                                     Debug.Print "child", vColItem
    '                        '            Me.txtVBJSONDeserializer.AppendText CStr(vColItem) & vbCrLf, True, True
    '                                Next
    
    '                                 '>>Test 1 End
    '
    '                                    '>>Test 2    ??????????????????
    '                                    Dim vCNKey As Variant
    '                                    Dim vCNItem As Variant
    '                                    For j = 0 To CN.Count - 1
    '
    '                                       vCNItem = CN.Item(j)
    '
    '                                    Next
    '                                    ''Test2 End ?????????????????
                                        
    '                            '>>Test 3  (Oolaf)
    '                            Dim FilteredNodes As cCollection'
    '                            Set FilteredNodes = New_c.Collection
    '                            Call ParseJSONFile(oDict.Item("children"))
                                 '>>Test 3 End
      
                             End If       'Exists children
                             
                        Case "Boolean"
                             vItem = oDict.Item(strKeyName)
                             
                             If Not IsEmpty(vItem) Then
                                Debug.Print "Boolean", strKeyName & "  :", CStr(vItem)
                            End If
                             
                             
                         Case "Null"
                            vItem = oDict.Item(strKeyName)
    
                        Case "Array"
     
                        Case "Object"
                        
                              'From cmdRun
                             'Look for Node of Interest.   Exists maybe a better construct than Alternative
                             If oDict.Exists("children") Then           '<< Alternative code:: If strKeyName = "children" Then
            
                                     For Each vItem In oDict.Item("children")
                                         vColItem = vItem
                                         Debug.Print vColItem
                            '            Me.txtVBJSONDeserializer.AppendText CStr(vColItem) & vbCrLf, True, True
                                    Next
                             
                                'get the current ChildNode into a separate JsonCol-Object
             '                   Set oCol = vObject
             '                   Set oCol = oDict.Item(strKeyName)
              
                                 Stop
                             End If       'Exists children
                             
                        End Select
    
    '                If strKeyName = "children" Then
    '
    '                   Dim vKeyCol As Variant
    '                   Dim vItemCol As Variant
    '                   Set oCol = vkeyName
    '
    '                   For Each vKeyCol In oCol.keys
    ' '                      vkeyName = vKeyCol
    '                      strKeyName = CStr(vKeyCol)
    '                  Next
    ''
    ''                  vItemCol = oCol.Item(1)
    '
    '                     'Did'nt work
    ''                     On Error Resume Next
    ''                     For Each vItem In oDict.Item(strKeyName)
    ''                             vColItem = vItem
    ''                            Me.txtVBJSONDeserializer.AppendText CStr(vColItem) & vbCrLf, True, True
    ''    '                             Debug.Print vColItem
    ''                     Next
    '                     'Didn't work end
    '
    '                End If    'key "children"
                    
                      
    '                On Error Resume Next
    '                For Each vItem In oDict(vkeyName)
    '                     vColItem = vItem
    '                     Debug.Print "Item:", vColItem
    '                Next
    
                Next key
                
           Next
           
    
    Exit Sub
            
            
    '   Set oDict = vObject
    '
    '
    '
    '
    '
    '                 'Enum dictionary to make sure Key exist
    '                For Each key In oDict.keys
    '
    '                    vkeyName = key
    '                    strKeyName = CStr(key)
    '
    '                    Debug.Print "Key:", strKeyName
    '
    '                    On Error Resume Next
    '                    For Each vItem In oDict(vkeyName)
    '                         vColItem = vItem
    '                         Debug.Print "Item:", vColItem
    '                    Next
    '
    '            Next key
          
     'Original from Here
                For Each oDict In vObject
                
    
                
                
                    '----------- Test
     'If oDict.Item("children").Exists Then Stop
                    
                    
                     'Enum dictionary to make sure Key exist
    ''                For Each key In oDict.keys
    ''                      vkeyName = key
    ''                      strKeyName = CStr(key)
    ''                Next key
            
                    'Enum dictionary to make sure Collection Items exist for this Key
    '                For Each key In oDict.keys
    '
    '                      vkeyName = key
    '                      strKeyName = CStr(key)
    '                      Debug.Print vkeyName
    '
    '                     If strKeyName = "Email" Then                        'alternate  On Error Resume Next
    '                        For Each vItem In oDict.Item("Email")           'oDict(vkeyName)
    '                             vColITem = vItem
    '                             Debug.Print vColITem
    '                        Next
    '                     End If
    '
    '                  'Alternate -- Returm the Item Value (Key Name known)
    '                    vItem = oDict.Item("Name")
    
    '
    '                Next key
    
    'Example to see if Key Exists
    'vExists = Dictionary.Exists (Key as String)
    
                    '----------- Test End
    
                
                
         '           Me.txtVBJSONDeserializer.AppendText "Name: " & oDict.item("Name") & vbCrLf                                  '<<Original 20171214
                        Me.txtVBJSONDeserializer.AppendText "Name: " & oDict.Item("Name") & vbCrLf, True, True
                        Me.txtVBJSONDeserializer.AppendText "Surname: " & oDict.Item("Surname") & vbCrLf, True, True          '<<dw Add 20171214
    '                    Me.txtVBJSONDeserializer.AppendText "EMail: " & oDict.Item("Email") & vbCrLf, True, True                    '<<dw Add 20171214   '<<why Empty
    Me.txtVBJSONDeserializer.AppendText "EMail: " & vbCrLf, True, True
                        'Email is a Collection
     '                   If oDict.Key    = "Email" Then        ''<< This Line Doesn't Work
     
                             For Each vItem In oDict.Item("Email")           'oDict(vkeyName)
                                 vColItem = vItem
                                Me.txtVBJSONDeserializer.AppendText CStr(vColItem) & vbCrLf, True, True
    '                             Debug.Print vColItem
                            Next
     '                    End If
        
        '---------  Test
        'Dim v As Variant
        'If oDict.item("EMail") Then
        '     Dim col1 As Collection
        '     Set col1 = New Collection
        '     For Each v In col1
        '         Debug.Print v(0)
        '     Next
        ' End If
        '---------  Test End
                         Me.txtVBJSONDeserializer.AppendText "Age: " & oDict.Item("Age") & vbCrLf, True, True                        '<<dw Add 20171214
                        Me.txtVBJSONDeserializer.AppendText "Married: " & oDict.Item("Married") & vbCrLf, True, True               '<<dw Add 20171214
        
        
        '            Me.txtVBJSONDeserializer.AppendText "name: " & oDict.item("name") & vbCrLf                                  '<<bookmarks 20171214
        
                    
                    DoEvents
                Next oDict
            End If
          
            
        End If
        
        
        '************
        'WRAPUP
        '************
        Screen.MousePointer = vbNormal
    
    End Sub
    ====================================
    Anyone get this to parse Firefox would like to know how?
    ====================================

    I debated to include this -- but on second thought -- here is the
    original module with all my Test Points so one can see how the parser
    is parsing. It generates a text file so one can compare against the original
    document (Firefox in this case). In regard to Firefox, after the "children"
    for some reason it wanted to used the Key generated for dateAdded for
    the following lastModified. Why is the question? My guess is that
    the pointer internal to the dictionary object being returned is some how
    being lost - but just a SWAG.
    Attached Files Attached Files
    Last edited by vb6forever; Dec 27th, 2017 at 04:54 AM. Reason: Add

  23. #23
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,253

    Re: Firefox - Find and Delete Bookmarks

    Quote Originally Posted by vb6forever View Post

    1) the first thing I did was download the JSON spec.

    http://ecma-international.org/public...T/ECMA-404.pdf
    Yep - for studying what JSON is (how it's structured internally), a document from the ECMA is certainly a good start.

    Quote Originally Posted by vb6forever View Post
    2) the second was make a decision regarding the amount of effort to learn RC5 versus
    seeing if I could locate a VB JSON parser, which I found.
    With regards to a JSON-parser *implementation* there is not much to study IMO.
    It will have a method for parsing (deserialization into a Root-Object) -
    and a second Method, to serialize from a given Object back into a JSON-string.

    Quote Originally Posted by vb6forever View Post
    3) In both cases -- RC5 or VB parser -- I had to climb a learning curve.
    Going the VB parser route I learned a lot about JSON, parsers
    -- BUT -- sadly I could never get the parser to do Firefox JSON.
    That's because the JSON-code you've found, contains still unresolved bugs -
    and as such should probably not be used as a "source to learn more about JSON or parsers".

    Going the RC5-route, you could have learned (in the same amount of time):
    - how to access, enumerate and use the fastest Collection-replacement for VB6 that's currently out there,
    - how JSON is structured (from the ECMA-PDF-document)
    - and would already have finished a *working* GUI-App around your concrete Problem

    If you want to check-out an alternative JSON-parser/serializer which does not depend on the RC5,
    you could look at dilettantes version (his code already undergoing a few "bug-fixing-cycles" -
    whether this "hardening" of the code was sufficient, to correctly parse the FireFox-backup-files, you'd have to test yourself).
    http://www.vbforums.com/showthread.p...rser-Generator

    Olaf

  24. #24
    Frenzied Member
    Join Date
    Dec 2008
    Location
    Melbourne Australia
    Posts
    1,487

    Re: Firefox - Find and Delete Bookmarks

    I expect you are liking the challenge ?
    But lazy OLD me would be looking for a pre-cooked solution, such as -
    https://www.techsupportalert.com/con...deadlink.htm-0

    Rob

  25. #25

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2017
    Posts
    863

    Re: Firefox - Find and Delete Bookmarks

    Olaf:

    That's because the JSON-code you've found, contains still unresolved bugs -
    and as such should probably not be used as a "source to learn more about JSON or parsers".
    So, I found out. Looking at JSON spec parser seems to follow it.

    Going the RC5-route, you could have learned ...
    As a library - with my understanding source not available - I ASSUMED (we know what that is)
    I figured I'd be dealing with a black box, unable to resolve any errors if they occurred.

    you could look at dilettantes version
    thanks for the link. Will take a look see. Based on revisions, not as simple to parse JSON as one would think and Standard outlines.

    ================
    Bobbles:
    Will check your link out. Thanks

  26. #26

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2017
    Posts
    863

    Re: Firefox - Find and Delete Bookmarks

    Downloaded dilettantes parser version 2.5.
    Changed sample txt file to point to Firefox "/bookmarks.json".
    Program loaded bookmarks file on left and attempted to parse on right.
    Gave it five minutes in compiled mode.
    Appearred stuck in loop.
    Had to use Ctrl-Alt_Delete to kill it.

    Interesting that bookmarks is so difficult to parse.
    Need a JSON break, but will try RC5 after the 1st.

  27. #27
    Member Dragokas's Avatar
    Join Date
    Aug 2015
    Location
    Ukraine
    Posts
    740

    Re: Firefox - Find and Delete Bookmarks

    vb6forever, can you please figure out what part of your json causes infinite loop? Or at least cut your file to minimal size to be able to reproduce (without personal info).
    Malware analyst, VirusNet developer, HiJackThis+ author || my CodeBank works

  28. #28

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2017
    Posts
    863

    Re: Firefox - Find and Delete Bookmarks

    Dragokas:

    Are you referring to my last post (thread #26, dilettantes parser) - or -- the other program addressed in the previous threads.
    In dilettantes parser case, I ran his program both from the VB IDE and compiled against my Firefox bookmarks file.
    Stuck in loop in both cases. I have NOT delved into the parser code so at this point can't help to ID where issue may reside.
    As previously stated, burned out on JSON parsing for now and taking a coding break till after the 1st.
    IN regard to cutting down the bookmark file -- it is quite large -- so not sure where to edit it
    in order to cut it and still remain a JSON file.
    Last edited by vb6forever; Dec 27th, 2017 at 09:07 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width