Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Comparing keys in a Json file with values in a List In python

I need to comapre the titles in this Json file with the titles in a list. My goal is to check what titles are equal to the values of this list and then print information about that title. For example if one of the titles is Bloons TD 6 I want to only print the corresponding description and viewableDate.

Here is what I have so far

response = requests.get("https://store-site-backend-static-ipv4.ak.epicgames.com/freeGamesPromotions?locale=en-US&country=US&allowCountries=US")

freeGameData = json.loads(response.text)
freeNowList = Epic_Scraper()

#freeNowList returns ['Bloons TD 6', 'Loop Hero']
#freeGameData returns the json listed below

The Json File looks like this

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

{
    "data": {
        "Catalog": {
            "searchStore": {
                "elements": [
                    {
                        "title": "Loop Hero",
                        "id": "db122f42b41f4dec927e0f280cf653bd",
                        "namespace": "ff50f85ed609454e80ac46d9496da34d",
                        "description": "The Lich has thrown the world into a timeless loop and plunged its inhabitants into never ending chaos. Wield an expanding deck of mystical cards to place enemies, buildings, and terrain along each unique expedition loop for the brave hero.",
                        "effectiveDate": "2021-03-04T18:00:00.000Z",
                        "offerType": "BASE_GAME",
                        "expiryDate": null,
                        "viewableDate": "2021-03-04T18:00:00.000Z",
                        "status": "ACTIVE",
                        "isCodeRedemptionOnly": false,
                    },
                    {
                        "title": "Bloons TD 6",
                        "id": "b27e3b556f1048b9824c7196f32afceb",
                        "namespace": "6a8dfa6e441e4f2f9048a98776c6077d",
                        "description": "The Bloons are back and better than ever! Get ready for a massive 3D tower defense game designed to give you hours and hours of the best strategy gaming available.",
                        "effectiveDate": "2022-07-19T12:00:00.000Z",
                        "offerType": "BASE_GAME",
                        "expiryDate": null,
                        "viewableDate": "2022-04-30T00:00:00.000Z",
                        "status": "ACTIVE",
                        "isCodeRedemptionOnly": false,
                    },
                    {
                        "title": "Destiny 2: Bungie 30th Anniversary Pack",
                        "id": "e7b9e222c7274dd28714aba2e06d2a01",
                        "namespace": "428115def4ca4deea9d69c99c5a5a99e",
                        "description": "The 30th Anniversary Pack includes a new Dungeon, Gjallarhorn Exotic Rocket Launcher, new weapons, armor, and much more.                    ",
                        "effectiveDate": "2022-08-23T13:00:00.000Z",
                        "offerType": "DLC",
                        "expiryDate": null,
                        "viewableDate": "2022-08-08T15:00:00.000Z",
                        "status": "ACTIVE",
                        "isCodeRedemptionOnly": false,
                        },
                    },

}

>Solution :

Loop through the innermost list of your json and only print the information if the title is in your list:

for e in freeGameData["data"]["Catalog"]["searchStore"]["elements"]:
    if e["title"] in freeNowList:
        print(e["description"])
        print(e["viewableDate"]+"\n")
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading