'How to Use If and else In google structured data Json

I am trying to make a custom blogger template and in this i am using google structured data Json

how to use if, else in this json if data:post.firstImageUrl is avilable then - data:post.firstImageUrl else my custom url https://example.com/logo.png

           "image": {
                    "@type": "ImageObject",
                    "width": 1920,
                    "height": 1080,
                    "if": "data:post.firstImageUrl",
                    "then": { 
                        "url": "data:post.firstImageUrl"},
                    "else": {
                        "url":  "https://example.com/logo.png",
                    },
                    "caption": "<data:post.title/>"
            },


Solution 1:[1]

you need to use <b:if> in the body section, and put the first condition of your CSS inside a tag, then the else, and then another tag with the second condition.

In your style tag:

                    "@type": "ImageObject";
                "width": 1920;
                "height": 1080;
                },
                "caption": "<data:post.title/>"
        },

So in the body section, you put the condition

<b:if cond='data:post.firstImageUrl;'>
<style>
"image": {"url": "data:post.firstImageUrl"}
</style>
<b:else/>
<style>
"image": {"url":  "https://example.com/logo.png"}
</style>

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ricardo Ramos