troubleshooting Question

Help! Parsing a Json file/result from the browser's LocalStorage.

Avatar of Daniel Gillett
Daniel GillettFlag for United Kingdom of Great Britain and Northern Ireland asked on
* Puppeteer* parser* data analysisJSON
44 Comments2 Solutions28 ViewsLast Modified:
Hello,

I need some help with parsing a json file/object.
The json is from the browsers localStorage.

I have the data already, but I am having trouble parsing it out properly and I am now crunched for time.

I can evaluate and retreive the data from LocalStorage:

let json = await page.evaluate(() => {
    const storage = localStorage.getItem("VistaOmnichannelComponents::browsing-domain-store");

    return json;
});

console.log(json)
fs.writeFileSync(filepath, JSON.stringify(json));

Open in new window

let json = await page.evaluate(() => {
    const storage = localStorage.getItem("VistaOmnichannelComponents::browsing-domain-store");
    return json;
});

console.log(json)
fs.writeFileSync(filepathJSON.stringify(json));

   Easily follow my tacks...
  1. goto: https://www.odeon.co.uk/cinemas/andover/
  2. Then go to google chrome dev lools -> Local Storage to look at the data.
  3. Use the evaluate code above (use puppeterr if you need to write the evaluate function).
I can send the data here if you need.  The file is about 60kb .json file.


I need to extract:
  • sitesById,
  • filmById
  • censoryRating
  • genresById
  • filmIdsForQuery

The data that I get is difficult to parse as it's all in one big object.
FYI - I had to create some [ ] around the data in order to start getting, but after hours, I'm not far enough and don't understand where/how to parse it correctly (many levels??)

Here are a few sample data objects I created, ready for the data from the LocalStorage:
[sitesById.json]
{
    "id": 1234,
    "name": "London Leicester Square",
    "location": {
        "latitude": 51.5184,
        "longitude": -0.129
    },
    "contactDetails": {
        "phoneNumbers": [
            {"number": "123456789"}
        ],
        "email": "",
        "address": [
            {"line1": "30 Elmer Avenue"}, 
            {"line2":""}, 
            {"city": "London"}
        ],
        "ianaTimeZoneName": "Europe/London"
    }
}

Open in new window

{
    "id"1234,
    "name""London Leicester Square",
    "location": {
        "latitude"51.5184,
        "longitude"-0.129
    },
    "contactDetails": {
        "phoneNumbers": [
            {"number""123456789"}
        ],
        "email""",
        "address": [
            {"line1""30 Elmer Avenue"}, 
            {"line2":""}, 
            {"city""London"}
        ],
        "ianaTimeZoneName""Europe/London"
    }
}

One more sample [filmsById] ... (I can finish it once I get the parsing working for each group)
{
    "id":"HO00001344",
    "title":"Black Widow",
    "synopsis":"The MCU’s Phase 4 kicks off in cinemas with Scarlett Johansson’s Black Widow returning for a prequel solo adventure that delves into the Avenger’s prehistory as a Soviet assassin. It also introduces a mysterious and deadly new supervillain, Taskmaster, and prepares the way for new heroes to rise...",
    "shortSynopsis":"Black Widow confronts the darker parts of her ledger when a dangerous conspiracy with ties to her past arises.",
    "censorRatingId":"0000000001",
    "censorRatingNote":null,
    "releaseDate":"2021-07-07",
    "runtimeInMinutes":134,
    "genreIds": [
        {"0":"0000000001"},
        {"1":"0000000003"},
        {"2":"0000000022"}
    ],
    "categories": [
        {"0": "NowShowing"}
    ],
    "moviexchangeReleaseId":"509a78b4-fe5b-418d-88aa-db333855dfb4",
    "hopk":"HO00001344",
    "hoCode":"A000001558",
    "distributorName":"WALT DISNEY STUDIOS INTERNTL"
}

Open in new window

{
    "id":"HO00001344",
    "title":"Black Widow",
    "synopsis":"The MCU’s Phase 4 kicks off in cinemas with Scarlett Johansson’s Black Widow returning for a prequel solo adventure that delves into the Avenger’s prehistory as a Soviet assassin. It also introduces a mysterious and deadly new supervillain, Taskmaster, and prepares the way for new heroes to rise. On the run after the events of Captain ",
    "shortSynopsis":"Black Widow confronts the darker parts of her ledger when a dangerous conspiracy with ties to her past arises.",
    "censorRatingId":"0000000001",
    "censorRatingNote":null,
    "releaseDate":"2021-07-07",
    "runtimeInMinutes":134,
    "genreIds": [
        {"0":"0000000001"},
        {"1":"0000000003"},
        {"2":"0000000022"}
    ],
    "categories": [
        {"0""NowShowing"}
    ],
    "hopk":"HO00001344",
    "hoCode":"A000001558",
    "distributorName":"WALT DISNEY STUDIOS INTERNTL"
}

I'm new to this site.  I really need the urgent support.

Hope you're out there!

Cheers!
ASKER CERTIFIED SOLUTION
Log in to continue reading
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform for $9.99/mo
View membership options
Unlock 2 Answers and 44 Comments.
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
The Value of Experts Exchange in My Daily IT Life

Experts Exchange (EE) has become my company's go-to resource to get answers. I've used EE to make decisions, solve problems and even save customers. OutagesIO has been a challenging project and... Keep reading >>

Mike

Owner of Outages.IO
Phoenix, Arizona, United States
Member Since 2016
Join a full scale community that combines the best parts of other tools into one platform.
Unlock 2 Answers and 44 Comments.
View membership options
“All of life is about relationships, and EE has made a virtual community a real community. It lifts everyone's boat.”
William Peck

Member since 2004