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

how to find key in json comes after variable key with python

how to find the "display_url" value after finding a certain id { id": 2799869337379524745 }

the main goal is to get only the display_url value after finding this key "id" with this value " 2799869337379524745 "

as you can see in this JSON there are 3 id/display_url keys that are the same but with different values
is there is a way to search for the display_url and get it if the script finds a certain id before it?

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

{
    "status_code": 0,
    "data": {
        "__type": "GraphSidecar",
        "items": [
            {
                "__type": "GraphImage",
                "title": "",
                "id": 2799854276157690472,
                "shortcode": "",
                "display_url": "https://instagram.frao1-2.fna.fbcdn.net/v/t51.2885-15/276983984_1278084093013655_9426266357493227_n.jpg?se=7&stp=dst-jpg_e35&_nc_ht=instagram.frao1-2.fna.fbcdn.net&_nc_cat=1&_nc_ohc=Agd6tOmDwWIAX9QRl47&edm=ALCvFkgBAAAA&ccb=7-4&ig_cache_key=Mjc5OTg1NDI3NjE1NzY5MDQ3Mg%3D%3D.2-ccb7-4&oh=00_AT81fTAWNb5z4xRKSvrlzYikB9SFH9fqC_Vz3Q_mpowzeA&oe=623CE3A3&_nc_sid=643ae9",
                "stats": {
                    "view_count": null,
                    "play_count": null,
                    "like_count": null,
                    "comment_count": null
                },
                "items": [
                    {
                        "width": 1284,
                        "height": 2282,
                        "url": "https://instagram.frao1-2.fna.fbcdn.net/v/t51.2885-15/276983984_1278084093013655_9426266357493227_n.jpg?se=7&stp=dst-jpg_e35&_nc_ht=instagram.frao1-2.fna.fbcdn.net&_nc_cat=1&_nc_ohc=Agd6tOmDwWIAX9QRl47&edm=ALCvFkgBAAAA&ccb=7-4&ig_cache_key=Mjc5OTg1NDI3NjE1NzY5MDQ3Mg%3D%3D.2-ccb7-4&oh=00_AT81fTAWNb5z4xRKSvrlzYikB9SFH9fqC_Vz3Q_mpowzeA&oe=623CE3A3&_nc_sid=643ae9"
                    },
                    {
                        "width": 412,
                        "height": 732,
                        "url": "https://instagram.frao1-2.fna.fbcdn.net/v/t51.2885-15/276983984_1278084093013655_9426266357493227_n.jpg?stp=dst-jpg_e35_p412x412&_nc_ht=instagram.frao1-2.fna.fbcdn.net&_nc_cat=1&_nc_ohc=Agd6tOmDwWIAX9QRl47&edm=ALCvFkgBAAAA&ccb=7-4&ig_cache_key=Mjc5OTg1NDI3NjE1NzY5MDQ3Mg%3D%3D.2-ccb7-4&oh=00_AT-Xh-RhlnxuYDEbpeybauDuzBljduFDo7gv605PN0waBA&oe=623CE3A3&_nc_sid=643ae9"
                    }
                ]
            },
            {
                "__type": "GraphVideo",
                "title": "",
                "id": 2799869337379524745,
                "shortcode": "",
                "display_url": "https://instagram.frao1-1.fna.fbcdn.net/v/t51.2885-15/276982171_368041468652651_1129111111982125674_n.jpg?stp=dst-jpg_e15&_nc_ht=instagram.frao1-1.fna.fbcdn.net&_nc_cat=111&_nc_ohc=Bn_fivVURfkAX96vioj&edm=ALCvFkgBAAAA&ccb=7-4&ig_cache_key=Mjc5OTg2OTMzNzM3OTUyNDc0NQ%3D%3D.2-ccb7-4&oh=00_AT82hfShwy8jgWnML_r9NwT5XHtz-GPo87AzP4WWLQLtQA&oe=623C67C8&_nc_sid=643ae9",
                "stats": {
                    "view_count": null,
                    "play_count": null,
                    "like_count": null,
                    "comment_count": null
                },
                "video_url": "https://instagram.frao1-1.fna.fbcdn.net/o1/v/t16/f1/m38/8B411302C790D400BFC917327ED000AB_video_dashinit.mp4?efg=eyJ2ZW5jb2RlX3RhZyI6InZ0c192b2RfdXJsZ2VuLjcyMC5zdG9yeS5iYXNlbGluZW9pbCJ9&_nc_ht=instagram.frao1-1.fna.fbcdn.net&_nc_cat=109&vs=1016973519224456_2663807264&_nc_vs=HBkcFQIYRGlnX3hwdl9lcGhlbWVyYWwvOEI0MTEzMDJDNzkwRDQwMEJGQzkxNzMyN0VEMDAwQUJfdmlkZW9fZGFzaGluaXQubXA0FQACyAEAKAAYABsBiAd1c2Vfb2lsATEVAAAmpNTf%2FLKO3z8VAigCQzMsF0AUAAAAAAAAGBVkYXNoX2Jhc2VsaW5lb2lsXzJfdjERAHXoBwA%3D&ccb=9-4&oe=623C67A5&oh=00_AT9fX3pzP1tg9MGCgA18lLMSNruXo4AZqemBNVmOFfLhDQ&_nc_sid=643ae9",
                "video_duration": 5
            }
        ],
        "owner": {
            "id": 2964949070,
            "username": "bellapoarch",
            "avatar_url": "https://instagram.frao1-2.fna.fbcdn.net/v/t51.2885-19/264213838_416586213515696_109261969756357041_n.jpg?stp=dst-jpg_s150x150&_nc_ht=instagram.frao1-2.fna.fbcdn.net&_nc_cat=1&_nc_ohc=bqlIwmkMbyQAX-5SGh_&edm=ALCvFkgBAAAA&ccb=7-4&oh=00_AT9FyyuMiYsJO1E2DckN_m0ow5_KLRDFgr8FXY2US_wT7Q&oe=62413ECB&_nc_sid=643ae9"
        }
    }
}

>Solution :

for i in data['data']['items']:
    if i['id'] == 2799869337379524745:
        print(i['display_url'])

is this what your looking for?

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