Validation
Creators provide TypeScript guidance. Validators inspect values at runtime and return diagnostics.
Import a validator
Import the specific validator you need from the validation subpath:
ts
import { validateProduct } from '@avensio/nuxt-jsonld/validation/classes/Product.validator'
import { createProduct } from '@avensio/nuxt-jsonld/creators'
const product = createProduct({
'@id': 'https://example.com/products/desk/#product',
name: 'Desk',
offers: {
'@type': 'Offer',
price: '299.00',
priceCurrency: 'EUR',
},
})
const diagnostics = await validateProduct(product)This explicit import keeps validation out of the normal graph registration path and loads only the requested validator entry.
Handle diagnostics
Each diagnostic identifies the affected path and includes a severity and message:
ts
const errors = diagnostics.filter(item => item.severity === 'error')
if (errors.length > 0) {
console.error('Invalid Product JSON-LD', errors)
}Choose where validation belongs in your application. For example, validate CMS data when it enters your system rather than on every render.
Preset composables do not import validation code implicitly. Validate preset data explicitly where it enters your application when runtime validation is required.