Rules Hub
Coding Rules Library
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Validate generated structured data against varied inputs before shipping
When emitting JSON-LD or other machine-readable structured data, run it through the official validator across multiple real entity types, not a single happy-path case.
Bad example
| 1 | // Build schema.org JSON-LD and ship it after eyeballing one product. |
| 2 | function buildProductJsonLd(product) { |
| 3 | return { |
| 4 | '@context': 'https://schema.org', |
| 5 | '@type': 'Product', |
| 6 | name: product.name, |
| 7 | offers: { '@type': 'Offer', price: product.price }, |
| 8 | }; |
| 9 | } |
| 10 | // Only tested with one in-stock product; never run through a validator. |
Explanation (EN)
Verifying generated structured data by glancing at a single example misses missing/invalid fields that only appear for other entity shapes (e.g. items without a price, different types). Search engines and other consumers silently reject or downrank malformed markup, so errors stay invisible until SEO suffers.
Objašnjenje (HR)
Provjera generiranih strukturiranih podataka pogledom na jedan primjer propušta nedostajuća ili nevaljana polja koja se pojave tek za druge oblike entiteta (npr. stavke bez cijene, drugačiji tipovi). Tražilice i drugi potrošači tiho odbacuju ili snižavaju neispravnu oznaku, pa greške ostaju nevidljive dok SEO ne počne trpjeti.
Good example
| 1 | // Build the JSON-LD, then validate it against the official validator |
| 2 | // (e.g. Google Rich Results Test) for several representative inputs: |
| 3 | // - a Product with offers |
| 4 | // - a Product without a price |
| 5 | // - a different @type entirely |
| 6 | // Fix every reported error and warning before merging. |
| 7 | function buildProductJsonLd(product) { |
| 8 | return { |
| 9 | '@context': 'https://schema.org', |
| 10 | '@type': 'Product', |
| 11 | name: product.name, |
| 12 | ...(product.price != null && { |
| 13 | offers: { '@type': 'Offer', price: product.price }, |
| 14 | }), |
| 15 | }; |
| 16 | } |
Explanation (EN)
Running the markup through the official validator across varied entity shapes surfaces missing-field warnings and type errors early, while they are cheap to fix, instead of discovering them after SEO impact.
Objašnjenje (HR)
Provlačenje oznake kroz službeni validator za različite oblike entiteta rano otkriva upozorenja o nedostajućim poljima i greške tipova, dok ih je jeftino popraviti, umjesto da ih otkrijemo tek nakon utjecaja na SEO.
Notes (EN)
Applies to any generated machine-readable contract: JSON-LD, RSS/Atom feeds, sitemaps, OpenGraph/Twitter card metadata.
Bilješke (HR)
Primjenjivo na svaki generirani strojno čitljiv ugovor: JSON-LD, RSS/Atom feedove, sitemape, OpenGraph/Twitter card metapodatke.