T
T
Temirlan Utegenov2021-02-19 14:05:08
Java
Temirlan Utegenov, 2021-02-19 14:05:08

What are the solutions to parse complex JSON with mutable schema structure?

Hello!
Junior in Java programming. In the process of learning, I set myself a training task for working with JSON.

When exporting bookmarks, Google Chrome generates an html file with information about all the bookmarks that were (including nesting in different folders).
I want to get the entire list of urls from that file, taking into account nesting, and then, based on the information received, get a new json with a different structure.

An example of such a Chrome export (my file has 25 thousand lines):

{
    "checksum": "...",
    "roots": {
       "bookmark_bar": {
        "children": [ {
            "children": [ {
               "children": [ {
                  "date_added": "13041636353545778",
                  "guid": "73d733d0-a949-4931-a309-ad5dd4e7d7aa",
                  "id": "7",
                  "name": "14 СЕРВИСОВ ДЛЯ СОЗДАНИЯ ИНФОГРАФИКИ — Medium",
                  "type": "url",
                  "url": "https://medium.com/p/d7eaf1d4de32"
                  }]
                  }]
                  }]
        },
         "date_added": "13219315411214455",
         "date_modified": "13244927499721694",
         "guid": "00000000-0000-4000-a000-000000000002",
         "id": "1",
         "name": "Bookmarks bar",
         "type": "folder"
      },
       "other": {
        "children": [  ],
        "date_added": "13219315411214461",
        "date_modified": "0",
        "guid": "00000000-0000-4000-a000-000000000003",
        "id": "2",
        "name": "Other bookmarks",
        "type": "folder"
     },
     "synced": {
        "children": [  ],
        "date_added": "13219315411214464",
        "date_modified": "13243676447438187",
        "guid": "00000000-0000-4000-a000-000000000004",
        "id": "3",
        "name": "Mobile bookmarks",
        "type": "folder"
     },
     
  "sync_metadata": "...",
  "version": 1
}


I read about various libraries here https://habr.com/ru/company/luxoft/blog/280782/
and I don’t see any problems for simple json, but I want to parse these bookmarks, while taking into account their nesting in folders (for example, get on urls output + what folder they were in).

In what way can this be done?
It is not necessary to give a decision, there may be advice in which direction to dig or where to look.
Thank you!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mark Struchkov, 2021-02-19
@upagge

Jackson to the rescue. I don't see any problem here.
You go through the folders and parse the data from them first into Java objects. I do not remember exactly how, but you can get the path to the file and simply add it to the object. Then you turn the object into JSON.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question