Skip to content

Installation & Usage ​

Bring the package into any Node or browser project, scaffold JSON-LD payloads, and keep them valid with the generated helpers.

Install ​

bash
pnpm add @avensio/jsonld-schema
# or
npm install @avensio/jsonld-schema

The distribution is fully ESM with .d.ts metadata, so TypeScript projects pick up types automatically. Need CommonJS? Rebuild the project locally with whatever bundler you prefer—an official CJS bundle is intentionally not published, since it would blow up the size.

Model data ​

Every Schema.org class ships with its interface and a creator helper.

ts
import type { Organization } from '@avensio/jsonld-schema/classes/Organization'
import { createOrganization } from '@avensio/jsonld-schema/creators'

const organization: Organization = createOrganization({
  name: 'Example Inc.',
  url: 'https://example.com'
})

Creators attach @context/@type and suggest (with TypeScript) property names and values.

Validate payloads ​

Validators live under @avensio/jsonld-schema/validation/… and return structured diagnostics.

ts
import type { Order } from '@avensio/jsonld-schema/classes/Order'
import { validateOrder } from '@avensio/jsonld-schema/validation/classes/Order.validator'

const diagnostics = await validateOrder({
  '@context': 'https://schema.org',
  '@type': 'Order',
  name: 'Demo order'
})

if (diagnostics.length) {
  diagnostics.forEach(diag => {
    console.warn(`${diag.severity.toUpperCase()} ${diag.path ?? '<root>'}: ${diag.message}`)
  })
}

For field-level checks, import property validators such as @avensio/jsonld-schema/validation/properties/url.validator or use helpers (validateArrayOfText, isUrl, …) from @avensio/jsonld-schema/validation/core.

Read the type preset ​

ts
import preset from '@avensio/jsonld-schema/presets/types/all' with { type: 'json' }

console.log(preset.types) // ["*"]

The published all preset is a lightweight descriptor for tools that want to include every generated Schema.org type.

Built with VitePress – Released under the MIT License.