Get an entry from a data file based on whether it exists or not

This is probably really easy but I can not figure it out.

  1. I have a datafile called “dogs.json”
  2. Some dogs have 2 images associated with them, some dogs have only 1 image.
    “image1”: “poodle1.jpg”,
    “image2”: “poodle2.jpg”,

    “image1”: “bulldog1.jpg”,
  3. I’m trying to find the correct method to show something if “image2” exists and show nothing if it does not (I’m trying to build an image carousel).

Any help is greatly appreciated, as I’m going round in circles!


Please show the code that isn’t working.

with and if. with is executed if a variable has content and if can check if the variable is empty.

Also, an image carousel should range normally through a variable count of images, not fixed defined image parameters with numbers. Maybe try using the search function of the discourse to find one of the many existing solutions here.