Skip to content

EvaLok/schema-org-json-ld

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2,985 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

schema-org-json-ld

PHP and TypeScript/JavaScript library for generating schema.org JSON-LD structured data for Google Rich Results. Covers all 31 Google Search Gallery categories backed by 89 schema classes/modules (88 primary schema types + 1 additional sub-type), with type-safe constructor-promoted properties and automatic serialization.

Validated against the Google Rich Results Test via the schema-org-json-ld-qc validation suite.

Tests PHP 8.1 PHP 8.2 PHP 8.3 PHP 8.4 PHP 8.5 TypeScript CI Node 20 Node 22 Node 24 npm License: MIT


Table of Contents


Installation

TypeScript / JavaScript

npm install @evabee/schema-org-json-ld
# or
yarn add @evabee/schema-org-json-ld
# or
bun add @evabee/schema-org-json-ld

PHP

composer require evabee/schema-org-json-ld

Note: The vendor name evabee is intentional. Due to Packagist requiring excessive GitHub permissions, the default evalok vendor namespace is unavailable. The package is otherwise identical.


Quick Start

PHP

<?php

use EvaLok\SchemaOrgJsonLd\v1\JsonLdGenerator;
use EvaLok\SchemaOrgJsonLd\v1\Schema\Article;
use EvaLok\SchemaOrgJsonLd\v1\Schema\Person;

$article = new Article(
	headline: 'How to Use Schema.org JSON-LD in PHP',
	author: new Person(name: 'Jane Smith'),
	datePublished: '2026-01-15',
);

$json = JsonLdGenerator::SchemaToJson(schema: $article);

// Embed in your HTML <head>:
// <script type="application/ld+json"><?= $json ?></script>
{
    "@context": "https://schema.org/",
    "@type": "Article",
    "headline": "How to Use Schema.org JSON-LD in PHP",
    "author": {
        "@type": "Person",
        "name": "Jane Smith"
    },
    "datePublished": "2026-01-15"
}

The pattern is always the same: instantiate a schema class, pass it to JsonLdGenerator::SchemaToJson(), and embed the result in a <script type="application/ld+json"> tag.

TypeScript / JavaScript

import {
  JsonLdGenerator, Product, Brand, Offer, ItemAvailability
} from '@evabee/schema-org-json-ld';

const product = new Product({
  name: 'Executive Anvil',
  image: ['https://example.com/anvil.jpg'],
  description: 'Sleekest anvil on the market',
  sku: 'ANVIL-001',
  offers: [new Offer({
    url: 'https://example.com/anvil',
    priceCurrency: 'USD',
    price: 119.99,
    availability: ItemAvailability.InStock,
  })],
  brand: new Brand({ name: 'ACME' }),
});

const jsonLd = JsonLdGenerator.schemaToJson(product);
// Returns a JSON-LD string

Supported Types

Google Rich Results category Supported schema types
Article Article, NewsArticle, BlogPosting
Breadcrumb BreadcrumbList, ListItem
Carousel ItemList, ListItem
Course Course, CourseInstance, Schedule
Dataset Dataset, DataDownload, DataCatalog, GeoShape
Discussion forum DiscussionForumPosting, Comment, InteractionCounter
Education Q&A Quiz, Question, Answer, AlignmentObject
Employer aggregate rating EmployerAggregateRating
Event Event, Place, VirtualLocation, Offer, EventStatusType, EventAttendanceModeEnumeration
FAQ FAQPage, Question, Answer
Image metadata ImageObject
Job posting JobPosting, Organization, Place, MonetaryAmount, AdministrativeArea, PropertyValue
Local business LocalBusiness, FoodEstablishment, Restaurant, Store, PostalAddress, GeoCoordinates, OpeningHoursSpecification, AggregateRating, Review, DayOfWeek
Math solver MathSolver, SolveMathAction
Movie Movie, Person, AggregateRating, Review
Organization Organization, PostalAddress, ContactPoint, MerchantReturnPolicy, MerchantReturnPolicySeasonalOverride, MemberProgram, MemberProgramTier, ShippingService, MerchantReturnEnumeration, RefundTypeEnumeration, ReturnFeesEnumeration, ReturnLabelSourceEnumeration, ReturnMethodEnumeration, TierBenefitEnumeration
Product Product, Offer, AggregateOffer, Brand, OfferShippingDetails, ShippingDeliveryTime, DefinedRegion, MonetaryAmount, QuantitativeValue, AggregateRating, Review, SizeSpecification, ProductGroup, PeopleAudience, Certification, UnitPriceSpecification, ShippingConditions, ServicePeriod, ShippingRateSettings, FulfillmentTypeEnumeration, OfferItemCondition, ItemAvailability
Profile page ProfilePage, Person, Organization
Q&A QAPage, Question, Answer
Recipe Recipe, Person, NutritionInformation, HowToStep, HowToSection, AggregateRating, VideoObject
Review snippet Review, AggregateRating, Rating, Thing
Software app SoftwareApplication, MobileApplication, WebApplication
Speakable SpeakableSpecification (via Article)
Subscription/paywalled content WebPageElement (via Article)
Vacation rental VacationRental, Accommodation, BedDetails, PostalAddress, AggregateRating, LocationFeatureSpecification
Video VideoObject, Clip, InteractionCounter, BroadcastEvent

Usage Examples

Article

Supports Article, NewsArticle, and BlogPosting. NewsArticle and BlogPosting extend Article and share the same constructor — only @type differs.

<?php

use EvaLok\SchemaOrgJsonLd\v1\JsonLdGenerator;
use EvaLok\SchemaOrgJsonLd\v1\Schema\Article;
use EvaLok\SchemaOrgJsonLd\v1\Schema\Organization;
use EvaLok\SchemaOrgJsonLd\v1\Schema\Person;

$article = new Article(
	headline: 'How to Use Schema.org JSON-LD in PHP',
	author: new Person(name: 'Jane Smith', url: 'https://example.com/jane'),
	datePublished: '2026-01-15',
	dateModified: '2026-02-01',
	image: ['https://example.com/photos/article.jpg'],
	publisher: new Organization(
		name: 'Example Media',
		url: 'https://example.com',
		logo: 'https://example.com/logo.png',
	),
);

$json = JsonLdGenerator::SchemaToJson(schema: $article);
{
    "@context": "https://schema.org/",
    "@type": "Article",
    "headline": "How to Use Schema.org JSON-LD in PHP",
    "author": {
        "@type": "Person",
        "name": "Jane Smith",
        "url": "https://example.com/jane"
    },
    "datePublished": "2026-01-15",
    "dateModified": "2026-02-01",
    "image": [
        "https://example.com/photos/article.jpg"
    ],
    "publisher": {
        "@type": "Organization",
        "name": "Example Media",
        "url": "https://example.com",
        "logo": "https://example.com/logo.png"
    }
}

TypeScript:

import { Article, JsonLdGenerator, Person } from '@evabee/schema-org-json-ld';

const article = new Article({
  headline: 'How to Use Schema.org JSON-LD in PHP',
  author: new Person({ name: 'Jane Smith', url: 'https://example.com/jane' }),
  datePublished: '2026-01-15',
});

const json = JsonLdGenerator.schemaToJson(article);

Output is identical to the PHP JSON example above.

Use NewsArticle or BlogPosting by substituting the class name — the constructor is identical:

use EvaLok\SchemaOrgJsonLd\v1\Schema\NewsArticle;
use EvaLok\SchemaOrgJsonLd\v1\Schema\BlogPosting;

$newsArticle = new NewsArticle(headline: 'Breaking: PHP 8.4 Released', datePublished: '2026-01-20');
$blogPost    = new BlogPosting(headline: 'My Journey Learning PHP',    datePublished: '2026-02-10');

Breadcrumb

<?php

use EvaLok\SchemaOrgJsonLd\v1\JsonLdGenerator;
use EvaLok\SchemaOrgJsonLd\v1\Schema\BreadcrumbList;
use EvaLok\SchemaOrgJsonLd\v1\Schema\ListItem;

$breadcrumb = new BreadcrumbList(
	itemListElement: [
		new ListItem(position: 1, name: 'Home',             item: 'https://example.com'),
		new ListItem(position: 2, name: 'Books',            item: 'https://example.com/books'),
		new ListItem(position: 3, name: 'Science & Nature', item: 'https://example.com/books/science'),
	],
);

$json = JsonLdGenerator::SchemaToJson(schema: $breadcrumb);
{
    "@context": "https://schema.org/",
    "@type": "BreadcrumbList",
    "itemListElement": [
        {
            "@type": "ListItem",
            "position": 1,
            "name": "Home",
            "item": "https://example.com"
        },
        {
            "@type": "ListItem",
            "position": 2,
            "name": "Books",
            "item": "https://example.com/books"
        },
        {
            "@type": "ListItem",
            "position": 3,
            "name": "Science & Nature",
            "item": "https://example.com/books/science"
        }
    ]
}

TypeScript:

import { BreadcrumbList, JsonLdGenerator, ListItem } from '@evabee/schema-org-json-ld';

const breadcrumb = new BreadcrumbList({
  itemListElement: [
    new ListItem({ position: 1, name: 'Home', item: 'https://example.com' }),
    new ListItem({ position: 2, name: 'Books', item: 'https://example.com/books' }),
    new ListItem({ position: 3, name: 'Science & Nature', item: 'https://example.com/books/science' }),
  ],
});

const json = JsonLdGenerator.schemaToJson(breadcrumb);

Output is identical to the PHP JSON example above.


Carousel

Use ItemList with ListItem entries pointing to the URLs of items in the carousel (articles, recipes, movies, etc.).

<?php

use EvaLok\SchemaOrgJsonLd\v1\JsonLdGenerator;
use EvaLok\SchemaOrgJsonLd\v1\Schema\ItemList;
use EvaLok\SchemaOrgJsonLd\v1\Schema\ListItem;

$carousel = new ItemList(
	itemListElement: [
		new ListItem(position: 1, url: 'https://example.com/articles/1'),
		new ListItem(position: 2, url: 'https://example.com/articles/2'),
		new ListItem(position: 3, url: 'https://example.com/articles/3'),
	],
	itemListOrder: 'ItemListOrderAscending',
	numberOfItems: 3,
);

$json = JsonLdGenerator::SchemaToJson(schema: $carousel);
{
    "@context": "https://schema.org/",
    "@type": "ItemList",
    "itemListElement": [
        {
            "@type": "ListItem",
            "position": 1,
            "url": "https://example.com/articles/1"
        },
        {
            "@type": "ListItem",
            "position": 2,
            "url": "https://example.com/articles/2"
        },
        {
            "@type": "ListItem",
            "position": 3,
            "url": "https://example.com/articles/3"
        }
    ],
    "itemListOrder": "ItemListOrderAscending",
    "numberOfItems": 3
}

TypeScript:

import { ItemList, JsonLdGenerator, ListItem } from '@evabee/schema-org-json-ld';

const carousel = new ItemList({
  itemListElement: [
    new ListItem({ position: 1, url: 'https://example.com/articles/1' }),
    new ListItem({ position: 2, url: 'https://example.com/articles/2' }),
    new ListItem({ position: 3, url: 'https://example.com/articles/3' }),
  ],
  itemListOrder: 'ItemListOrderAscending',
  numberOfItems: 3,
});

const json = JsonLdGenerator.schemaToJson(carousel);

Output is identical to the PHP JSON example above.


Course

<?php

use EvaLok\SchemaOrgJsonLd\v1\JsonLdGenerator;
use EvaLok\SchemaOrgJsonLd\v1\Schema\AggregateRating;
use EvaLok\SchemaOrgJsonLd\v1\Schema\Course;
use EvaLok\SchemaOrgJsonLd\v1\Schema\CourseInstance;
use EvaLok\SchemaOrgJsonLd\v1\Enum\ItemAvailability;
use EvaLok\SchemaOrgJsonLd\v1\Schema\Offer;
use EvaLok\SchemaOrgJsonLd\v1\Enum\OfferItemCondition;
use EvaLok\SchemaOrgJsonLd\v1\Schema\Organization;
use EvaLok\SchemaOrgJsonLd\v1\Schema\Person;
use EvaLok\SchemaOrgJsonLd\v1\Schema\Schedule;

$course = new Course(
	name: 'Advanced PHP Development',
	description: 'Master PHP 8.x features, design patterns, and best practices.',
	provider: new Organization(name: 'PHP Academy', url: 'https://phpacademy.example.com'),
	hasCourseInstance: [
		new CourseInstance(
			courseMode: 'online',
			instructor: new Person(name: 'Prof. Alice Dev'),
			courseSchedule: new Schedule(repeatFrequency: 'P1W', repeatCount: 12),
		),
	],
	offers: [
		new Offer(
			url: 'https://phpacademy.example.com/advanced-php',
			priceCurrency: 'USD',
			price: 199.0,
			itemCondition: OfferItemCondition::NewCondition,
			availability: ItemAvailability::InStock,
		),
	],
	courseCode: 'CS101',
	inLanguage: 'en',
	totalHistoricalEnrollment: 15000,
	aggregateRating: new AggregateRating(ratingValue: 4.8, reviewCount: 342, bestRating: 5),
	image: 'https://example.com/images/web-dev-course.jpg',
);

$json = JsonLdGenerator::SchemaToJson(schema: $course);
{
    "@context": "https://schema.org/",
    "@type": "Course",
    "name": "Advanced PHP Development",
    "description": "Master PHP 8.x features, design patterns, and best practices.",
    "provider": {
        "@type": "Organization",
        "name": "PHP Academy",
        "url": "https://phpacademy.example.com"
    },
    "offers": [
        {
            "@type": "Offer",
            "url": "https://phpacademy.example.com/advanced-php",
            "priceCurrency": "USD",
            "price": 199,
            "itemCondition": "https://schema.org/NewCondition",
            "availability": "https://schema.org/InStock"
        }
    ],
    "hasCourseInstance": [
        {
            "@type": "CourseInstance",
            "courseMode": "online",
            "instructor": {
                "@type": "Person",
                "name": "Prof. Alice Dev"
            },
            "courseSchedule": {
                "@type": "Schedule",
                "repeatFrequency": "P1W",
                "repeatCount": 12
            }
        }
    ],
    "courseCode": "CS101",
    "inLanguage": "en",
    "totalHistoricalEnrollment": 15000,
    "aggregateRating": {
        "@type": "AggregateRating",
        "ratingValue": 4.8,
        "bestRating": 5,
        "reviewCount": 342
    },
    "image": "https://example.com/images/web-dev-course.jpg"
}

TypeScript:

import { Course, JsonLdGenerator, Organization } from '@evabee/schema-org-json-ld';

const course = new Course({
  name: 'Advanced PHP Development',
  description: 'Master PHP 8.x features, design patterns, and best practices.',
  provider: new Organization({ name: 'PHP Academy', url: 'https://phpacademy.example.com' }),
});

const json = JsonLdGenerator.schemaToJson(course);

Output is identical to the PHP JSON example above.


Dataset

<?php

use EvaLok\SchemaOrgJsonLd\v1\JsonLdGenerator;
use EvaLok\SchemaOrgJsonLd\v1\Schema\DataDownload;
use EvaLok\SchemaOrgJsonLd\v1\Schema\Dataset;
use EvaLok\SchemaOrgJsonLd\v1\Schema\Organization;

$dataset = new Dataset(
	name: 'PHP Developer Survey 2025',
	description: 'Annual survey of PHP developer demographics and tool usage.',
	url: 'https://example.com/datasets/php-survey-2025',
	sameAs: 'https://doi.org/10.5281/zenodo.1234567',
	creator: new Organization(name: 'PHP Foundation'),
	license: 'https://creativecommons.org/licenses/by/4.0/',
	keywords: ['PHP', 'developer survey', 'programming'],
	isAccessibleForFree: true,
	temporalCoverage: '2020-01-01/2025-12-31',
	distribution: [
		new DataDownload(
			contentUrl: 'https://example.com/datasets/php-survey-2025.csv',
			encodingFormat: 'text/csv',
		),
	],
	version: '2.1',
	citation: 'Doe, J. (2026). Example Climate Dataset. Zenodo.',
);

$json = JsonLdGenerator::SchemaToJson(schema: $dataset);
{
    "@context": "https://schema.org/",
    "@type": "Dataset",
    "name": "PHP Developer Survey 2025",
    "description": "Annual survey of PHP developer demographics and tool usage.",
    "url": "https://example.com/datasets/php-survey-2025",
    "sameAs": "https://doi.org/10.5281/zenodo.1234567",
    "creator": {
        "@type": "Organization",
        "name": "PHP Foundation"
    },
    "license": "https://creativecommons.org/licenses/by/4.0/",
    "keywords": [
        "PHP",
        "developer survey",
        "programming"
    ],
    "isAccessibleForFree": true,
    "temporalCoverage": "2020-01-01/2025-12-31",
    "distribution": [
        {
            "@type": "DataDownload",
            "contentUrl": "https://example.com/datasets/php-survey-2025.csv",
            "encodingFormat": "text/csv"
        }
    ],
    "version": "2.1",
    "citation": "Doe, J. (2026). Example Climate Dataset. Zenodo."
}

TypeScript:

import { Dataset, JsonLdGenerator } from '@evabee/schema-org-json-ld';

const dataset = new Dataset({
  name: 'PHP Developer Survey 2025',
  description: 'Annual survey of PHP developer demographics and tool usage.',
});

const json = JsonLdGenerator.schemaToJson(dataset);

Output is identical to the PHP JSON example above.


Discussion Forum

<?php

use EvaLok\SchemaOrgJsonLd\v1\JsonLdGenerator;
use EvaLok\SchemaOrgJsonLd\v1\Schema\DiscussionForumPosting;
use EvaLok\SchemaOrgJsonLd\v1\Schema\Person;

$post = new DiscussionForumPosting(
	author: new Person(name: 'ForumUser42', url: 'https://forum.example.com/users/42'),
	datePublished: '2026-01-10T14:30:00+00:00',
	text: 'What is the best way to handle database migrations in PHP?',
	headline: 'Best approach for DB migrations?',
	url: 'https://forum.example.com/threads/db-migrations',
);

$json = JsonLdGenerator::SchemaToJson(schema: $post);
{
    "@context": "https://schema.org/",
    "@type": "DiscussionForumPosting",
    "author": {
        "@type": "Person",
        "name": "ForumUser42",
        "url": "https://forum.example.com/users/42"
    },
    "datePublished": "2026-01-10T14:30:00+00:00",
    "text": "What is the best way to handle database migrations in PHP?",
    "headline": "Best approach for DB migrations?",
    "url": "https://forum.example.com/threads/db-migrations"
}

TypeScript:

import { DiscussionForumPosting, JsonLdGenerator, Person } from '@evabee/schema-org-json-ld';

const post = new DiscussionForumPosting({
  author: new Person({ name: 'ForumUser42', url: 'https://forum.example.com/users/42' }),
  datePublished: '2026-01-10T14:30:00+00:00',
  text: 'What is the best way to handle database migrations in PHP?',
  headline: 'Best approach for DB migrations?',
  url: 'https://forum.example.com/threads/db-migrations',
});

const json = JsonLdGenerator.schemaToJson(post);

Output is identical to the PHP JSON example above.


Education Q&A

<?php

use EvaLok\SchemaOrgJsonLd\v1\JsonLdGenerator;
use EvaLok\SchemaOrgJsonLd\v1\Schema\AlignmentObject;
use EvaLok\SchemaOrgJsonLd\v1\Schema\Answer;
use EvaLok\SchemaOrgJsonLd\v1\Schema\Question;
use EvaLok\SchemaOrgJsonLd\v1\Schema\Quiz;

$quiz = new Quiz(
	hasPart: [
		new Question(
			name: 'What does PHP stand for?',
			eduQuestionType: 'MultipleChoice',
			acceptedAnswer: new Answer(text: 'PHP: Hypertext Preprocessor'),
			suggestedAnswer: [
				new Answer(text: 'Personal Home Page'),
				new Answer(text: 'Hypertext Preprocessor'),
			],
		),
	],
	name: 'PHP Basics Quiz',
	about: 'PHP programming language fundamentals',
	educationalAlignment: new AlignmentObject(
		alignmentType: 'educationalLevel',
		targetName: 'Beginner',
	),
);

$json = JsonLdGenerator::SchemaToJson(schema: $quiz);
{
    "@context": "https://schema.org/",
    "@type": "Quiz",
    "hasPart": [
        {
            "@type": "Question",
            "name": "What does PHP stand for?",
            "acceptedAnswer": {
                "@type": "Answer",
                "text": "PHP: Hypertext Preprocessor"
            },
            "suggestedAnswer": [
                {
                    "@type": "Answer",
                    "text": "Personal Home Page"
                },
                {
                    "@type": "Answer",
                    "text": "Hypertext Preprocessor"
                }
            ],
            "eduQuestionType": "MultipleChoice"
        }
    ],
    "about": "PHP programming language fundamentals",
    "educationalAlignment": {
        "@type": "AlignmentObject",
        "alignmentType": "educationalLevel",
        "targetName": "Beginner"
    },
    "name": "PHP Basics Quiz"
}

TypeScript:

import { JsonLdGenerator, Question, Quiz } from '@evabee/schema-org-json-ld';

const quiz = new Quiz({
  hasPart: [new Question({ name: 'What does PHP stand for?' })],
  name: 'PHP Basics Quiz',
});

const json = JsonLdGenerator.schemaToJson(quiz);

Output is identical to the PHP JSON example above.


Employer Aggregate Rating

<?php

use EvaLok\SchemaOrgJsonLd\v1\JsonLdGenerator;
use EvaLok\SchemaOrgJsonLd\v1\Schema\EmployerAggregateRating;
use EvaLok\SchemaOrgJsonLd\v1\Schema\Organization;

$employerRating = new EmployerAggregateRating(
	itemReviewed: new Organization(name: 'TechCorp Inc.', url: 'https://techcorp.example.com'),
	ratingValue: 4.2,
	ratingCount: 350,
	bestRating: 5,
	worstRating: 1,
);

$json = JsonLdGenerator::SchemaToJson(schema: $employerRating);
{
    "@context": "https://schema.org/",
    "@type": "EmployerAggregateRating",
    "itemReviewed": {
        "@type": "Organization",
        "name": "TechCorp Inc.",
        "url": "https://techcorp.example.com"
    },
    "ratingValue": 4.2,
    "ratingCount": 350,
    "bestRating": 5,
    "worstRating": 1
}

TypeScript:

import { EmployerAggregateRating, JsonLdGenerator, Organization } from '@evabee/schema-org-json-ld';

const employerRating = new EmployerAggregateRating({
  itemReviewed: new Organization({ name: 'TechCorp Inc.', url: 'https://techcorp.example.com' }),
  ratingValue: 4.2,
  ratingCount: 350,
  bestRating: 5,
  worstRating: 1,
});

const json = JsonLdGenerator.schemaToJson(employerRating);

Output is identical to the PHP JSON example above.


Event

<?php

use EvaLok\SchemaOrgJsonLd\v1\JsonLdGenerator;
use EvaLok\SchemaOrgJsonLd\v1\Schema\Event;
use EvaLok\SchemaOrgJsonLd\v1\Enum\EventAttendanceModeEnumeration;
use EvaLok\SchemaOrgJsonLd\v1\Enum\EventStatusType;
use EvaLok\SchemaOrgJsonLd\v1\Enum\ItemAvailability;
use EvaLok\SchemaOrgJsonLd\v1\Schema\Offer;
use EvaLok\SchemaOrgJsonLd\v1\Enum\OfferItemCondition;
use EvaLok\SchemaOrgJsonLd\v1\Schema\Organization;
use EvaLok\SchemaOrgJsonLd\v1\Schema\Place;
use EvaLok\SchemaOrgJsonLd\v1\Schema\PostalAddress;
use EvaLok\SchemaOrgJsonLd\v1\Schema\VirtualLocation;

$event = new Event(
	name: 'PHP Conference 2026',
	startDate: '2026-06-15T09:00:00+00:00',
	location: [
		new Place(
			name: 'Convention Center',
			address: new PostalAddress(
				streetAddress: '123 Main St',
				addressLocality: 'San Francisco',
				addressRegion: 'CA',
				postalCode: '94102',
				addressCountry: 'US',
			),
		),
		new VirtualLocation(url: 'https://stream.example.com/phpconf2026', name: 'Livestream'),
	],
	description: 'The premier PHP conference on the west coast.',
	endDate: '2026-06-17T17:00:00+00:00',
	eventAttendanceMode: EventAttendanceModeEnumeration::MixedEventAttendanceMode,
	eventStatus: EventStatusType::EventScheduled,
	image: ['https://example.com/phpconf2026.jpg'],
	organizer: new Organization(name: 'PHP Foundation', url: 'https://php.foundation'),
	offers: [
		new Offer(
			url: 'https://phpconf2026.example.com/tickets',
			priceCurrency: 'USD',
			price: 299.0,
			itemCondition: OfferItemCondition::NewCondition,
			availability: ItemAvailability::InStock,
		),
	],
);

$json = JsonLdGenerator::SchemaToJson(schema: $event);
{
    "@context": "https://schema.org/",
    "@type": "Event",
    "name": "PHP Conference 2026",
    "startDate": "2026-06-15T09:00:00+00:00",
    "location": [
        {
            "@type": "Place",
            "name": "Convention Center",
            "address": {
                "@type": "PostalAddress",
                "streetAddress": "123 Main St",
                "addressLocality": "San Francisco",
                "addressRegion": "CA",
                "postalCode": "94102",
                "addressCountry": "US"
            }
        },
        {
            "@type": "VirtualLocation",
            "url": "https://stream.example.com/phpconf2026",
            "name": "Livestream"
        }
    ],
    "description": "The premier PHP conference on the west coast.",
    "endDate": "2026-06-17T17:00:00+00:00",
    "eventAttendanceMode": "https://schema.org/MixedEventAttendanceMode",
    "eventStatus": "https://schema.org/EventScheduled",
    "image": [
        "https://example.com/phpconf2026.jpg"
    ],
    "offers": [
        {
            "@type": "Offer",
            "url": "https://phpconf2026.example.com/tickets",
            "priceCurrency": "USD",
            "price": 299,
            "itemCondition": "https://schema.org/NewCondition",
            "availability": "https://schema.org/InStock"
        }
    ],
    "organizer": {
        "@type": "Organization",
        "name": "PHP Foundation",
        "url": "https://php.foundation"
    }
}

TypeScript:

import { Event, JsonLdGenerator, Place } from '@evabee/schema-org-json-ld';

const event = new Event({
  name: 'PHP Conference 2026',
  startDate: '2026-06-15T09:00:00+00:00',
  location: [new Place({ name: 'Convention Center' })],
});

const json = JsonLdGenerator.schemaToJson(event);

Output is identical to the PHP JSON example above.


FAQ

<?php

use EvaLok\SchemaOrgJsonLd\v1\JsonLdGenerator;
use EvaLok\SchemaOrgJsonLd\v1\Schema\Answer;
use EvaLok\SchemaOrgJsonLd\v1\Schema\FAQPage;
use EvaLok\SchemaOrgJsonLd\v1\Schema\Question;

$faq = new FAQPage(
	mainEntity: [
		new Question(
			name: 'What is schema.org JSON-LD?',
			acceptedAnswer: new Answer(
				text: 'Schema.org JSON-LD is a method of encoding structured data in a JSON format to help search engines understand your content.',
			),
		),
		new Question(
			name: 'Does Google support JSON-LD?',
			acceptedAnswer: new Answer(
				text: 'Yes, Google recommends JSON-LD as the preferred format for structured data markup.',
			),
		),
	],
);

$json = JsonLdGenerator::SchemaToJson(schema: $faq);
{
    "@context": "https://schema.org/",
    "@type": "FAQPage",
    "mainEntity": [
        {
            "@type": "Question",
            "name": "What is schema.org JSON-LD?",
            "acceptedAnswer": {
                "@type": "Answer",
                "text": "Schema.org JSON-LD is a method of encoding structured data in a JSON format to help search engines understand your content."
            }
        },
        {
            "@type": "Question",
            "name": "Does Google support JSON-LD?",
            "acceptedAnswer": {
                "@type": "Answer",
                "text": "Yes, Google recommends JSON-LD as the preferred format for structured data markup."
            }
        }
    ]
}

TypeScript:

import { FAQPage, JsonLdGenerator, Question } from '@evabee/schema-org-json-ld';

const faq = new FAQPage({
  mainEntity: [new Question({ name: 'What is schema.org JSON-LD?' })],
});

const json = JsonLdGenerator.schemaToJson(faq);

Output is identical to the PHP JSON example above.


Image Metadata

<?php

use EvaLok\SchemaOrgJsonLd\v1\JsonLdGenerator;
use EvaLok\SchemaOrgJsonLd\v1\Schema\ImageObject;
use EvaLok\SchemaOrgJsonLd\v1\Schema\Organization;

$image = new ImageObject(
	contentUrl: 'https://example.com/photos/sunset.jpg',
	license: 'https://creativecommons.org/licenses/by/4.0/',
	acquireLicensePage: 'https://example.com/license',
	creditText: 'Example Photographer',
	creator: new Organization(name: 'Example Studio'),
	copyrightNotice: '© 2026 Example Studio',
);

$json = JsonLdGenerator::SchemaToJson(schema: $image);
{
    "@context": "https://schema.org/",
    "@type": "ImageObject",
    "contentUrl": "https://example.com/photos/sunset.jpg",
    "license": "https://creativecommons.org/licenses/by/4.0/",
    "acquireLicensePage": "https://example.com/license",
    "creditText": "Example Photographer",
    "copyrightNotice": "© 2026 Example Studio",
    "creator": {
        "@type": "Organization",
        "name": "Example Studio"
    }
}

TypeScript:

import { ImageObject, JsonLdGenerator } from '@evabee/schema-org-json-ld';

const image = new ImageObject({
  contentUrl: 'https://example.com/photos/sunset.jpg',
});

const json = JsonLdGenerator.schemaToJson(image);

Output is identical to the PHP JSON example above.


Job Posting

<?php

use EvaLok\SchemaOrgJsonLd\v1\JsonLdGenerator;
use EvaLok\SchemaOrgJsonLd\v1\Schema\AdministrativeArea;
use EvaLok\SchemaOrgJsonLd\v1\Schema\JobPosting;
use EvaLok\SchemaOrgJsonLd\v1\Schema\MonetaryAmount;
use EvaLok\SchemaOrgJsonLd\v1\Schema\Organization;
use EvaLok\SchemaOrgJsonLd\v1\Schema\Place;
use EvaLok\SchemaOrgJsonLd\v1\Schema\PostalAddress;
use EvaLok\SchemaOrgJsonLd\v1\Schema\PropertyValue;

$job = new JobPosting(
	title: 'Senior PHP Developer',
	description: 'We are looking for an experienced PHP developer to join our team.',
	datePosted: '2026-01-15',
	hiringOrganization: new Organization(
		name: 'TechCorp Inc.',
		url: 'https://techcorp.example.com',
		logo: 'https://techcorp.example.com/logo.png',
	),
	jobLocation: new Place(
		name: 'TechCorp HQ',
		address: new PostalAddress(
			streetAddress: '456 Tech Ave',
			addressLocality: 'Austin',
			addressRegion: 'TX',
			postalCode: '78701',
			addressCountry: 'US',
		),
	),
	baseSalary: new MonetaryAmount(currency: 'USD', minValue: 120000, maxValue: 160000),
	employmentType: 'FULL_TIME',
	validThrough: '2026-03-15',
	applicantLocationRequirements: new AdministrativeArea(name: 'United States'),
	jobLocationType: 'TELECOMMUTE',
	directApply: true,
	identifier: new PropertyValue(name: 'TechCorp', value: 'TC-2026-PHP-001'),
);

$json = JsonLdGenerator::SchemaToJson(schema: $job);
{
    "@context": "https://schema.org/",
    "@type": "JobPosting",
    "title": "Senior PHP Developer",
    "description": "We are looking for an experienced PHP developer to join our team.",
    "datePosted": "2026-01-15",
    "hiringOrganization": {
        "@type": "Organization",
        "name": "TechCorp Inc.",
        "url": "https://techcorp.example.com",
        "logo": "https://techcorp.example.com/logo.png"
    },
    "jobLocation": {
        "@type": "Place",
        "name": "TechCorp HQ",
        "address": {
            "@type": "PostalAddress",
            "streetAddress": "456 Tech Ave",
            "addressLocality": "Austin",
            "addressRegion": "TX",
            "postalCode": "78701",
            "addressCountry": "US"
        }
    },
    "baseSalary": {
        "@type": "MonetaryAmount",
        "currency": "USD",
        "minValue": 120000,
        "maxValue": 160000
    },
    "employmentType": "FULL_TIME",
    "validThrough": "2026-03-15",
    "applicantLocationRequirements": {
        "@type": "AdministrativeArea",
        "name": "United States"
    },
    "jobLocationType": "TELECOMMUTE",
    "directApply": true,
    "identifier": {
        "@type": "PropertyValue",
        "name": "TechCorp",
        "value": "TC-2026-PHP-001"
    }
}

TypeScript:

import { JobPosting, JsonLdGenerator, Organization } from '@evabee/schema-org-json-ld';

const job = new JobPosting({
  title: 'Senior PHP Developer',
  description: 'We are looking for an experienced PHP developer to join our team.',
  datePosted: '2026-01-15',
  hiringOrganization: new Organization({
    name: 'TechCorp Inc.',
    url: 'https://techcorp.example.com',
    logo: 'https://techcorp.example.com/logo.png',
  }),
});

const json = JsonLdGenerator.schemaToJson(job);

Output is identical to the PHP JSON example above.


Local Business

<?php

use EvaLok\SchemaOrgJsonLd\v1\JsonLdGenerator;
use EvaLok\SchemaOrgJsonLd\v1\Schema\AggregateRating;
use EvaLok\SchemaOrgJsonLd\v1\Enum\DayOfWeek;
use EvaLok\SchemaOrgJsonLd\v1\Schema\GeoCoordinates;
use EvaLok\SchemaOrgJsonLd\v1\Schema\LocalBusiness;
use EvaLok\SchemaOrgJsonLd\v1\Schema\OpeningHoursSpecification;
use EvaLok\SchemaOrgJsonLd\v1\Schema\Person;
use EvaLok\SchemaOrgJsonLd\v1\Schema\PostalAddress;
use EvaLok\SchemaOrgJsonLd\v1\Schema\Rating;
use EvaLok\SchemaOrgJsonLd\v1\Schema\Restaurant;
use EvaLok\SchemaOrgJsonLd\v1\Schema\Review;

$localBusiness = new LocalBusiness(
	name: 'The Corner Café',
	address: new PostalAddress(
		streetAddress: '789 Oak Street',
		addressLocality: 'Portland',
		addressRegion: 'OR',
		postalCode: '97201',
		addressCountry: 'US',
	),
	url: 'https://cornercafe.example.com',
	telephone: '+15035550100',
	description: 'A cozy neighborhood cafe serving artisan coffee and pastries.',
	image: ['https://cornercafe.example.com/photos/storefront.jpg'],
	priceRange: '$$',
	geo: new GeoCoordinates(latitude: 45.5231, longitude: -122.6765),
	openingHoursSpecification: [
		new OpeningHoursSpecification(dayOfWeek: DayOfWeek::Monday,   opens: '07:00', closes: '18:00'),
		new OpeningHoursSpecification(dayOfWeek: DayOfWeek::Saturday, opens: '08:00', closes: '16:00'),
	],
	aggregateRating: new AggregateRating(ratingValue: 4.7, reviewCount: 218, bestRating: 5),
	review: new Review(
		author: new Person(name: 'Jane D.'),
		reviewRating: new Rating(ratingValue: 5, bestRating: 5),
		reviewBody: 'Best coffee in Portland!',
	),
	menu: 'https://cornercafe.example.com/menu',
	servesCuisine: 'Coffee, Pastries',
	logo: 'https://cornercafe.example.com/logo.png',
);

$json = JsonLdGenerator::SchemaToJson(schema: $localBusiness);
$restaurant = new Restaurant(
	name: 'Fine Dining Place',
	address: new PostalAddress(
		streetAddress: '100 Main St',
		addressLocality: 'Portland',
		addressRegion: 'OR',
		postalCode: '97201',
		addressCountry: 'US',
	),
	servesCuisine: 'French',
	acceptsReservations: true,
	priceRange: '$$$',
);
{
    "@context": "https://schema.org/",
    "@type": "LocalBusiness",
    "name": "The Corner Café",
    "address": {
        "@type": "PostalAddress",
        "streetAddress": "789 Oak Street",
        "addressLocality": "Portland",
        "addressRegion": "OR",
        "postalCode": "97201",
        "addressCountry": "US"
    },
    "url": "https://cornercafe.example.com",
    "telephone": "+15035550100",
    "description": "A cozy neighborhood cafe serving artisan coffee and pastries.",
    "image": [
        "https://cornercafe.example.com/photos/storefront.jpg"
    ],
    "priceRange": "$$",
    "geo": {
        "@type": "GeoCoordinates",
        "latitude": 45.5231,
        "longitude": -122.6765
    },
    "openingHoursSpecification": [
        {
            "@type": "OpeningHoursSpecification",
            "dayOfWeek": "https://schema.org/Monday",
            "opens": "07:00",
            "closes": "18:00"
        },
        {
            "@type": "OpeningHoursSpecification",
            "dayOfWeek": "https://schema.org/Saturday",
            "opens": "08:00",
            "closes": "16:00"
        }
    ],
    "aggregateRating": {
        "@type": "AggregateRating",
        "ratingValue": 4.7,
        "bestRating": 5,
        "reviewCount": 218
    },
    "review": {
        "@type": "Review",
        "author": {
            "@type": "Person",
            "name": "Jane D."
        },
        "reviewRating": {
            "@type": "Rating",
            "ratingValue": 5,
            "bestRating": 5
        },
        "reviewBody": "Best coffee in Portland!"
    },
    "menu": "https://cornercafe.example.com/menu",
    "servesCuisine": "Coffee, Pastries",
    "logo": "https://cornercafe.example.com/logo.png"
}

TypeScript:

import { JsonLdGenerator, LocalBusiness, PostalAddress } from '@evabee/schema-org-json-ld';

const localBusiness = new LocalBusiness({
  name: 'The Corner Café',
  address: new PostalAddress({ streetAddress: '789 Oak Street' }),
});

const json = JsonLdGenerator.schemaToJson(localBusiness);

Output is identical to the PHP JSON example above.


Math Solver

<?php

use EvaLok\SchemaOrgJsonLd\v1\JsonLdGenerator;
use EvaLok\SchemaOrgJsonLd\v1\Schema\MathSolver;
use EvaLok\SchemaOrgJsonLd\v1\Schema\SolveMathAction;

$mathSolver = new MathSolver(
	url: 'https://example.com/math-solver',
	usageInfo: 'https://example.com/math-solver/usage',
	potentialAction: new SolveMathAction(
		target: 'https://example.com/math-solver?expression={math_expression}',
		mathExpressionInput: 'x^2 + 4x + 4 = 0',
	),
	name: 'Equation Solver',
	inLanguage: 'en',
	learningResourceType: 'Math solver',
	assesses: ['Algebra', 'Equations'],
);

$json = JsonLdGenerator::SchemaToJson(schema: $mathSolver);
{
    "@context": "https://schema.org/",
    "@type": [
        "MathSolver",
        "LearningResource"
    ],
    "url": "https://example.com/math-solver",
    "usageInfo": "https://example.com/math-solver/usage",
    "potentialAction": {
        "@type": "SolveMathAction",
        "target": "https://example.com/math-solver?expression={math_expression}",
        "mathExpression-input": "x^2 + 4x + 4 = 0"
    },
    "name": "Equation Solver",
    "inLanguage": "en",
    "learningResourceType": "Math solver",
    "assesses": [
        "Algebra",
        "Equations"
    ]
}

TypeScript:

import { JsonLdGenerator, MathSolver, SolveMathAction } from '@evabee/schema-org-json-ld';

const mathSolver = new MathSolver({
  url: 'https://example.com/math-solver',
  usageInfo: 'https://example.com/math-solver/usage',
  potentialAction: new SolveMathAction({
    target: 'https://example.com/math-solver?expression={math_expression}',
    mathExpressionInput: 'x^2 + 4x + 4 = 0',
  }),
  name: 'Equation Solver',
  inLanguage: 'en',
  learningResourceType: 'Math solver',
  assesses: ['Algebra', 'Equations'],
});

const json = JsonLdGenerator.schemaToJson(mathSolver);

Output is identical to the PHP JSON example above.


Movie

<?php

use EvaLok\SchemaOrgJsonLd\v1\JsonLdGenerator;
use EvaLok\SchemaOrgJsonLd\v1\Schema\AggregateRating;
use EvaLok\SchemaOrgJsonLd\v1\Schema\Movie;
use EvaLok\SchemaOrgJsonLd\v1\Schema\Person;

$movie = new Movie(
	name: 'The PHP Chronicles',
	image: 'https://example.com/movies/php-chronicles-poster.jpg',
	dateCreated: '2026-03-01',
	director: new Person(name: 'Alice Director'),
	aggregateRating: new AggregateRating(ratingValue: 7.5, ratingCount: 4200, bestRating: 10),
	description: 'An epic journey through the history of PHP.',
	actor: [new Person(name: 'Bob Actor'), new Person(name: 'Carol Actress')],
);

$json = JsonLdGenerator::SchemaToJson(schema: $movie);
{
    "@context": "https://schema.org/",
    "@type": "Movie",
    "name": "The PHP Chronicles",
    "image": "https://example.com/movies/php-chronicles-poster.jpg",
    "aggregateRating": {
        "@type": "AggregateRating",
        "ratingValue": 7.5,
        "bestRating": 10,
        "ratingCount": 4200
    },
    "dateCreated": "2026-03-01",
    "director": {
        "@type": "Person",
        "name": "Alice Director"
    },
    "description": "An epic journey through the history of PHP.",
    "actor": [
        {
            "@type": "Person",
            "name": "Bob Actor"
        },
        {
            "@type": "Person",
            "name": "Carol Actress"
        }
    ]
}

TypeScript:

import { JsonLdGenerator, Movie } from '@evabee/schema-org-json-ld';

const movie = new Movie({
  name: 'The PHP Chronicles',
  image: 'https://example.com/movies/php-chronicles-poster.jpg',
});

const json = JsonLdGenerator.schemaToJson(movie);

Output is identical to the PHP JSON example above.


Organization

<?php

use EvaLok\SchemaOrgJsonLd\v1\JsonLdGenerator;
use EvaLok\SchemaOrgJsonLd\v1\Schema\ContactPoint;
use EvaLok\SchemaOrgJsonLd\v1\Schema\Organization;
use EvaLok\SchemaOrgJsonLd\v1\Schema\PostalAddress;
use EvaLok\SchemaOrgJsonLd\v1\Schema\QuantitativeValue;

$org = new Organization(
	name: 'PHP Foundation',
	url: 'https://php.foundation',
	logo: 'https://php.foundation/logo.png',
	description: 'Supporting the PHP ecosystem.',
	email: 'info@php.foundation',
	telephone: '+1-800-PHP-HELP',
	address: new PostalAddress(
		streetAddress: '1 Open Source Way',
		addressLocality: 'San Francisco',
		addressRegion: 'CA',
		postalCode: '94105',
		addressCountry: 'US',
	),
	contactPoint: new ContactPoint(
		telephone: '+1-800-PHP-HELP',
		contactType: 'customer support',
		availableLanguage: 'English',
	),
	sameAs: ['https://github.com/php', 'https://twitter.com/php_net'],
	foundingDate: '2021-11-22',
	alternateName: 'The PHP Foundation',
	legalName: 'PHP Foundation Inc.',
	numberOfEmployees: new QuantitativeValue(value: 50),
	// hasMerchantReturnPolicy: new MerchantReturnPolicy(...),
	// hasMemberProgram: new MemberProgram(...),
	// hasShippingService: new ShippingService(...),
);

$json = JsonLdGenerator::SchemaToJson(schema: $org);
{
    "@context": "https://schema.org/",
    "@type": "Organization",
    "name": "PHP Foundation",
    "url": "https://php.foundation",
    "logo": "https://php.foundation/logo.png",
    "description": "Supporting the PHP ecosystem.",
    "email": "info@php.foundation",
    "telephone": "+1-800-PHP-HELP",
    "address": {
        "@type": "PostalAddress",
        "streetAddress": "1 Open Source Way",
        "addressLocality": "San Francisco",
        "addressRegion": "CA",
        "postalCode": "94105",
        "addressCountry": "US"
    },
    "contactPoint": {
        "@type": "ContactPoint",
        "telephone": "+1-800-PHP-HELP",
        "contactType": "customer support",
        "availableLanguage": "English"
    },
    "sameAs": [
        "https://github.com/php",
        "https://twitter.com/php_net"
    ],
    "foundingDate": "2021-11-22",
    "alternateName": "The PHP Foundation",
    "legalName": "PHP Foundation Inc.",
    "numberOfEmployees": {
        "@type": "QuantitativeValue",
        "value": 50
    }
}

TypeScript:

import { JsonLdGenerator, Organization } from '@evabee/schema-org-json-ld';

const org = new Organization({
  name: 'PHP Foundation',
  url: 'https://php.foundation',
});

const json = JsonLdGenerator.schemaToJson(org);

Output is identical to the PHP JSON example above.

hasMerchantReturnPolicy, hasMemberProgram, and hasShippingService accept MerchantReturnPolicy, MemberProgram, and ShippingService objects respectively (or arrays of those objects).

Additional organization identifier fields supported by Organization:

  • taxID
  • vatID
  • naics
  • duns
  • leiCode
  • iso6523Code
  • globalLocationNumber

Product

<?php

use EvaLok\SchemaOrgJsonLd\v1\JsonLdGenerator;
use EvaLok\SchemaOrgJsonLd\v1\Schema\Brand;
use EvaLok\SchemaOrgJsonLd\v1\Schema\Certification;
use EvaLok\SchemaOrgJsonLd\v1\Schema\DefinedRegion;
use EvaLok\SchemaOrgJsonLd\v1\Enum\ItemAvailability;
use EvaLok\SchemaOrgJsonLd\v1\Schema\MonetaryAmount;
use EvaLok\SchemaOrgJsonLd\v1\Schema\Offer;
use EvaLok\SchemaOrgJsonLd\v1\Enum\OfferItemCondition;
use EvaLok\SchemaOrgJsonLd\v1\Schema\OfferShippingDetails;
use EvaLok\SchemaOrgJsonLd\v1\Schema\Organization;
use EvaLok\SchemaOrgJsonLd\v1\Schema\PeopleAudience;
use EvaLok\SchemaOrgJsonLd\v1\Schema\Product;
use EvaLok\SchemaOrgJsonLd\v1\Schema\ProductGroup;
use EvaLok\SchemaOrgJsonLd\v1\Schema\QuantitativeValue;
use EvaLok\SchemaOrgJsonLd\v1\Schema\ShippingDeliveryTime;
use EvaLok\SchemaOrgJsonLd\v1\Schema\SizeSpecification;
use EvaLok\SchemaOrgJsonLd\v1\Schema\UnitPriceSpecification;

$product = new Product(
	name: 'Executive Anvil',
	image: [
		'https://example.com/photos/1x1/photo.jpg',
		'https://example.com/photos/4x3/photo.jpg',
		'https://example.com/photos/16x9/photo.jpg',
	],
	description: "Sleeker than ACME's Classic Anvil, the Executive Anvil is perfect for the business traveler looking for something to drop from a height.",
	sku: '0446310786',
	brand: new Brand(name: 'ACME (tm)'),
	mpn: 'ACME0444246625',
	weight: new QuantitativeValue(value: 55.67, unitCode: 'LBR'),
	size: new SizeSpecification(name: 'M', sizeGroup: 'Mens', sizeSystem: 'US'),
	isVariantOf: new ProductGroup(
		name: 'Executive Anvil',
		productGroupID: 'anvil-executive-family',
		variesBy: ['https://schema.org/size'],
	),
	audience: new PeopleAudience(suggestedGender: 'Male', suggestedMinAge: 18),
	hasCertification: new Certification(
		name: 'Business Traveler Safety Standard',
		issuedBy: new Organization(name: 'ACME Compliance Board'),
	),
	offers: [
		new Offer(
			url: 'https://example.com/anvil',
			priceCurrency: 'USD',
			price: 119.99,
			itemCondition: OfferItemCondition::NewCondition,
			availability: ItemAvailability::InStock,
			priceSpecification: new UnitPriceSpecification(
				price: 119.99,
				priceCurrency: 'USD',
				priceType: 'https://schema.org/StrikethroughPrice',
			),
			shippingDetails: [
				new OfferShippingDetails(
					shippingDestination: new DefinedRegion(addressCountry: 'US', addressRegion: ['CA', 'NV', 'AZ']),
					shippingRate: new MonetaryAmount(value: 3.49, currency: 'USD'),
					deliveryTime: new ShippingDeliveryTime(
						handlingTime: new QuantitativeValue(unitCode: 'DAY', minValue: 0, maxValue: 1),
						transitTime: new QuantitativeValue(unitCode: 'DAY', minValue: 1, maxValue: 5),
					),
				),
				new OfferShippingDetails(
					shippingDestination: new DefinedRegion(addressCountry: 'US', addressRegion: ['AK']),
					doesNotShip: true,
				),
			],
		),
	],
);

$json = JsonLdGenerator::SchemaToJson(schema: $product);
{
    "@context": "https://schema.org/",
    "@type": "Product",
    "name": "Executive Anvil",
    "image": [
        "https://example.com/photos/1x1/photo.jpg",
        "https://example.com/photos/4x3/photo.jpg",
        "https://example.com/photos/16x9/photo.jpg"
    ],
    "description": "Sleeker than ACME's Classic Anvil, the Executive Anvil is perfect for the business traveler looking for something to drop from a height.",
    "sku": "0446310786",
    "offers": [
        {
            "@type": "Offer",
            "url": "https://example.com/anvil",
            "priceCurrency": "USD",
            "price": 119.99,
            "itemCondition": "https://schema.org/NewCondition",
            "availability": "https://schema.org/InStock",
            "priceSpecification": {
                "@type": "UnitPriceSpecification",
                "price": 119.99,
                "priceCurrency": "USD",
                "priceType": "https://schema.org/StrikethroughPrice"
            },
            "shippingDetails": [
                {
                    "@type": "OfferShippingDetails",
                    "shippingDestination": {
                        "@type": "DefinedRegion",
                        "addressCountry": "US",
                        "addressRegion": ["CA", "NV", "AZ"]
                    },
                    "shippingRate": {
                        "@type": "MonetaryAmount",
                        "currency": "USD",
                        "value": 3.49
                    },
                    "deliveryTime": {
                        "@type": "ShippingDeliveryTime",
                        "handlingTime": {
                            "@type": "QuantitativeValue",
                            "unitCode": "DAY",
                            "minValue": 0,
                            "maxValue": 1
                        },
                        "transitTime": {
                            "@type": "QuantitativeValue",
                            "unitCode": "DAY",
                            "minValue": 1,
                            "maxValue": 5
                        }
                    }
                },
                {
                    "@type": "OfferShippingDetails",
                    "shippingDestination": {
                        "@type": "DefinedRegion",
                        "addressCountry": "US",
                        "addressRegion": ["AK"]
                    },
                    "doesNotShip": true
                }
            ]
        }
    ],
    "brand": {
        "@type": "Brand",
        "name": "ACME (tm)"
    },
    "mpn": "ACME0444246625",
    "weight": {
        "@type": "QuantitativeValue",
        "value": 55.67,
        "unitCode": "LBR"
    },
    "size": {
        "@type": "SizeSpecification",
        "name": "M",
        "sizeGroup": "Mens",
        "sizeSystem": "US"
    },
    "isVariantOf": {
        "@type": "ProductGroup",
        "name": "Executive Anvil",
        "productGroupID": "anvil-executive-family",
        "variesBy": [
            "https://schema.org/size"
        ]
    },
    "audience": {
        "@type": "PeopleAudience",
        "suggestedGender": "Male",
        "suggestedMinAge": 18
    },
    "hasCertification": {
        "@type": "Certification",
        "name": "Business Traveler Safety Standard",
        "issuedBy": {
            "@type": "Organization",
            "name": "ACME Compliance Board"
        }
    }
}

TypeScript:

import { ItemAvailability, JsonLdGenerator, Offer, Product } from '@evabee/schema-org-json-ld';

const product = new Product({
  name: 'Executive Anvil',
  image: ['https://example.com/photos/1x1/photo.jpg'],
  description: "Sleeker than ACME's Classic Anvil, the Executive Anvil is perfect for the business traveler looking for something to drop from a height.",
  sku: '0446310786',
  offers: [
    new Offer({
      url: 'https://example.com/anvil',
      priceCurrency: 'USD',
      price: 119.99,
      availability: ItemAvailability.InStock,
    }),
  ],
});

const json = JsonLdGenerator.schemaToJson(product);

Output is identical to the PHP JSON example above.


Profile Page

<?php

use EvaLok\SchemaOrgJsonLd\v1\JsonLdGenerator;
use EvaLok\SchemaOrgJsonLd\v1\Schema\Person;
use EvaLok\SchemaOrgJsonLd\v1\Schema\ProfilePage;

$profile = new ProfilePage(
	mainEntity: new Person(
		name: 'Alice Dev',
		url: 'https://example.com/alice',
		image: 'https://example.com/alice/photo.jpg',
		jobTitle: 'Senior PHP Developer',
		description: 'Open source contributor and PHP enthusiast.',
		sameAs: ['https://github.com/alicedev', 'https://linkedin.com/in/alicedev'],
	),
	dateCreated: '2020-01-01',
	dateModified: '2026-01-15',
);

$json = JsonLdGenerator::SchemaToJson(schema: $profile);
{
    "@context": "https://schema.org/",
    "@type": "ProfilePage",
    "mainEntity": {
        "@type": "Person",
        "name": "Alice Dev",
        "url": "https://example.com/alice",
        "image": "https://example.com/alice/photo.jpg",
        "jobTitle": "Senior PHP Developer",
        "sameAs": [
            "https://github.com/alicedev",
            "https://linkedin.com/in/alicedev"
        ],
        "description": "Open source contributor and PHP enthusiast."
    },
    "dateCreated": "2020-01-01",
    "dateModified": "2026-01-15"
}

TypeScript:

import { JsonLdGenerator, Person, ProfilePage } from '@evabee/schema-org-json-ld';

const profile = new ProfilePage({
  mainEntity: new Person({ name: 'Alice Dev', url: 'https://example.com/alice' }),
  dateCreated: '2020-01-01',
  dateModified: '2026-01-15',
});

const json = JsonLdGenerator.schemaToJson(profile);

Output is identical to the PHP JSON example above.


Q&A

<?php

use EvaLok\SchemaOrgJsonLd\v1\JsonLdGenerator;
use EvaLok\SchemaOrgJsonLd\v1\Schema\Answer;
use EvaLok\SchemaOrgJsonLd\v1\Schema\QAPage;
use EvaLok\SchemaOrgJsonLd\v1\Schema\Question;

$qa = new QAPage(
	mainEntity: new Question(
		name: 'How do I install Composer?',
		text: 'I am new to PHP and want to know how to install Composer on Ubuntu.',
		answerCount: 2,
		acceptedAnswer: new Answer(
			text: 'Run: curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer',
			upvoteCount: 142,
		),
		suggestedAnswer: [
			new Answer(
				text: 'You can also download the installer from https://getcomposer.org/download/ and run it manually.',
				upvoteCount: 38,
			),
		],
	),
);

$json = JsonLdGenerator::SchemaToJson(schema: $qa);
{
    "@context": "https://schema.org/",
    "@type": "QAPage",
    "mainEntity": {
        "@type": "Question",
        "name": "How do I install Composer?",
        "acceptedAnswer": {
            "@type": "Answer",
            "text": "Run: curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer",
            "upvoteCount": 142
        },
        "suggestedAnswer": [
            {
                "@type": "Answer",
                "text": "You can also download the installer from https://getcomposer.org/download/ and run it manually.",
                "upvoteCount": 38
            }
        ],
        "answerCount": 2,
        "text": "I am new to PHP and want to know how to install Composer on Ubuntu."
    }
}

TypeScript:

import { JsonLdGenerator, QAPage, Question } from '@evabee/schema-org-json-ld';

const qa = new QAPage({
  mainEntity: new Question({ name: 'How do I install Composer?' }),
});

const json = JsonLdGenerator.schemaToJson(qa);

Output is identical to the PHP JSON example above.


Recipe

<?php

use EvaLok\SchemaOrgJsonLd\v1\JsonLdGenerator;
use EvaLok\SchemaOrgJsonLd\v1\Schema\AggregateRating;
use EvaLok\SchemaOrgJsonLd\v1\Schema\HowToSection;
use EvaLok\SchemaOrgJsonLd\v1\Schema\HowToStep;
use EvaLok\SchemaOrgJsonLd\v1\Schema\NutritionInformation;
use EvaLok\SchemaOrgJsonLd\v1\Schema\Person;
use EvaLok\SchemaOrgJsonLd\v1\Schema\Recipe;

$recipe = new Recipe(
	name: "Grandma's Apple Pie",
	image: [
		'https://example.com/photos/applepie-1x1.jpg',
		'https://example.com/photos/applepie-4x3.jpg',
	],
	author: new Person(name: 'Grandma Rose'),
	datePublished: '2026-01-05',
	description: 'The best apple pie recipe, passed down through generations.',
	prepTime: 'PT30M',
	cookTime: 'PT1H',
	totalTime: 'PT1H30M',
	recipeYield: '8 servings',
	recipeCategory: 'Dessert',
	recipeCuisine: 'American',
	recipeIngredient: [
		'6 large apples, peeled and sliced',
		'3/4 cup sugar',
		'1 teaspoon cinnamon',
		'2 cups all-purpose flour',
	],
	recipeInstructions: [
		new HowToSection(
			name: 'Prepare pie',
			itemListElement: [
				new HowToStep(name: 'Prepare filling', text: 'Mix sliced apples with sugar and cinnamon in a large bowl.'),
				new HowToStep(name: 'Make crust', text: 'Combine flour, butter, and water to form a dough. Roll out for crust.'),
				new HowToStep(name: 'Bake', text: 'Pour filling into crust-lined pie dish, cover with top crust, bake at 375°F for 1 hour.'),
			],
		),
	],
	nutrition: new NutritionInformation(calories: '320 calories', fatContent: '12 g', carbohydrateContent: '52 g'),
	aggregateRating: new AggregateRating(ratingValue: 4.9, ratingCount: 1200, bestRating: 5),
);

$json = JsonLdGenerator::SchemaToJson(schema: $recipe);
{
    "@context": "https://schema.org/",
    "@type": "Recipe",
    "name": "Grandma's Apple Pie",
    "image": [
        "https://example.com/photos/applepie-1x1.jpg",
        "https://example.com/photos/applepie-4x3.jpg"
    ],
    "author": {
        "@type": "Person",
        "name": "Grandma Rose"
    },
    "datePublished": "2026-01-05",
    "description": "The best apple pie recipe, passed down through generations.",
    "prepTime": "PT30M",
    "cookTime": "PT1H",
    "totalTime": "PT1H30M",
    "recipeYield": "8 servings",
    "recipeCategory": "Dessert",
    "recipeCuisine": "American",
    "recipeIngredient": [
        "6 large apples, peeled and sliced",
        "3/4 cup sugar",
        "1 teaspoon cinnamon",
        "2 cups all-purpose flour"
    ],
    "recipeInstructions": [
        {
            "@type": "HowToSection",
            "name": "Prepare pie",
            "itemListElement": [
                {
                    "@type": "HowToStep",
                    "text": "Mix sliced apples with sugar and cinnamon in a large bowl.",
                    "name": "Prepare filling"
                },
                {
                    "@type": "HowToStep",
                    "text": "Combine flour, butter, and water to form a dough. Roll out for crust.",
                    "name": "Make crust"
                },
                {
                    "@type": "HowToStep",
                    "text": "Pour filling into crust-lined pie dish, cover with top crust, bake at 375°F for 1 hour.",
                    "name": "Bake"
                }
            ]
        }
    ],
    "nutrition": {
        "@type": "NutritionInformation",
        "calories": "320 calories",
        "fatContent": "12 g",
        "carbohydrateContent": "52 g"
    },
    "aggregateRating": {
        "@type": "AggregateRating",
        "ratingValue": 4.9,
        "bestRating": 5,
        "ratingCount": 1200
    }
}

TypeScript:

import { JsonLdGenerator, Recipe } from '@evabee/schema-org-json-ld';

const recipe = new Recipe({
  name: "Grandma's Apple Pie",
  image: ['https://example.com/photos/applepie-1x1.jpg', 'https://example.com/photos/applepie-4x3.jpg'],
});

const json = JsonLdGenerator.schemaToJson(recipe);

Output is identical to the PHP JSON example above.


Review Snippet

<?php

use EvaLok\SchemaOrgJsonLd\v1\JsonLdGenerator;
use EvaLok\SchemaOrgJsonLd\v1\Schema\AggregateRating;
use EvaLok\SchemaOrgJsonLd\v1\Schema\Rating;
use EvaLok\SchemaOrgJsonLd\v1\Schema\Review;

// Standalone review
$review = new Review(
	author: 'Jane Reviewer',
	reviewRating: new Rating(ratingValue: 4, bestRating: 5),
	reviewBody: 'Excellent product! Works exactly as described and arrived quickly.',
	datePublished: '2026-01-20',
	name: 'Great product',
);

$json = JsonLdGenerator::SchemaToJson(schema: $review);
{
    "@context": "https://schema.org/",
    "@type": "Review",
    "author": "Jane Reviewer",
    "reviewRating": {
        "@type": "Rating",
        "ratingValue": 4,
        "bestRating": 5
    },
    "reviewBody": "Excellent product! Works exactly as described and arrived quickly.",
    "datePublished": "2026-01-20",
    "name": "Great product"
}

TypeScript:

import { JsonLdGenerator, Rating, Review } from '@evabee/schema-org-json-ld';

const review = new Review({
  author: 'Jane Reviewer',
  reviewRating: new Rating({ ratingValue: 4, bestRating: 5 }),
  reviewBody: 'Excellent product! Works exactly as described and arrived quickly.',
  datePublished: '2026-01-20',
  name: 'Great product',
});

const json = JsonLdGenerator.schemaToJson(review);

Output is identical to the PHP JSON example above.

Review and AggregateRating are typically embedded inside a Product, Movie, Recipe, etc. rather than used standalone. The review and aggregateRating properties are available on all relevant schema types.


Software App

Supports SoftwareApplication, MobileApplication, and WebApplication. The subtype classes share the same constructor as SoftwareApplication.

<?php

use EvaLok\SchemaOrgJsonLd\v1\JsonLdGenerator;
use EvaLok\SchemaOrgJsonLd\v1\Schema\AggregateRating;
use EvaLok\SchemaOrgJsonLd\v1\Enum\ItemAvailability;
use EvaLok\SchemaOrgJsonLd\v1\Schema\MobileApplication;
use EvaLok\SchemaOrgJsonLd\v1\Schema\Offer;
use EvaLok\SchemaOrgJsonLd\v1\Enum\OfferItemCondition;
use EvaLok\SchemaOrgJsonLd\v1\Schema\Person;
use EvaLok\SchemaOrgJsonLd\v1\Schema\Rating;
use EvaLok\SchemaOrgJsonLd\v1\Schema\Review;
use EvaLok\SchemaOrgJsonLd\v1\Schema\SoftwareApplication;

$app = new SoftwareApplication(
	name: 'CodeHelper Pro',
	offers: new Offer(
		url: 'https://codehelper.example.com/buy',
		priceCurrency: 'USD',
		price: 9.99,
		itemCondition: OfferItemCondition::NewCondition,
		availability: ItemAvailability::InStock,
	),
	aggregateRating: new AggregateRating(ratingValue: 4.6, ratingCount: 8900, bestRating: 5),
	applicationCategory: 'DeveloperApplication',
	operatingSystem: 'Windows, macOS, Linux',
	review: new Review(
		author: new Person(name: 'Mike R.'),
		reviewRating: new Rating(ratingValue: 5, bestRating: 5),
		reviewBody: 'Excellent photo editor!',
	),
	description: 'A powerful photo editing application for professionals.',
	screenshot: 'https://example.com/screenshots/photoeditor-main.png',
);

$json = JsonLdGenerator::SchemaToJson(schema: $app);
{
    "@context": "https://schema.org/",
    "@type": "SoftwareApplication",
    "name": "CodeHelper Pro",
    "offers": {
        "@type": "Offer",
        "url": "https://codehelper.example.com/buy",
        "priceCurrency": "USD",
        "price": 9.99,
        "itemCondition": "https://schema.org/NewCondition",
        "availability": "https://schema.org/InStock"
    },
    "aggregateRating": {
        "@type": "AggregateRating",
        "ratingValue": 4.6,
        "bestRating": 5,
        "ratingCount": 8900
    },
    "applicationCategory": "DeveloperApplication",
    "operatingSystem": "Windows, macOS, Linux",
    "review": {
        "@type": "Review",
        "author": {
            "@type": "Person",
            "name": "Mike R."
        },
        "reviewRating": {
            "@type": "Rating",
            "ratingValue": 5,
            "bestRating": 5
        },
        "reviewBody": "Excellent photo editor!"
    },
    "description": "A powerful photo editing application for professionals.",
    "screenshot": "https://example.com/screenshots/photoeditor-main.png"
}

TypeScript:

import { AggregateRating, ItemAvailability, JsonLdGenerator, Offer, SoftwareApplication } from '@evabee/schema-org-json-ld';

const app = new SoftwareApplication({
  name: 'CodeHelper Pro',
  offers: new Offer({
    url: 'https://codehelper.example.com/buy',
    priceCurrency: 'USD',
    price: 9.99,
    availability: ItemAvailability.InStock,
  }),
  aggregateRating: new AggregateRating({ ratingValue: 4.6, ratingCount: 8900 }),
});

const json = JsonLdGenerator.schemaToJson(app);

Output is identical to the PHP JSON example above.

Use MobileApplication or WebApplication by substituting the class name:

$mobileApp = new MobileApplication(name: 'CodeHelper Mobile', offers: $offer, aggregateRating: $rating, operatingSystem: 'ANDROID, IOS');
$webApp    = new WebApplication(name: 'CodeHelper Web',       offers: $offer, aggregateRating: $rating);

Speakable

The SpeakableSpecification is used via the speakable property on Article (and its subtypes).

<?php

use EvaLok\SchemaOrgJsonLd\v1\JsonLdGenerator;
use EvaLok\SchemaOrgJsonLd\v1\Schema\Article;
use EvaLok\SchemaOrgJsonLd\v1\Schema\SpeakableSpecification;

$article = new Article(
	headline: 'Latest News: PHP Reaches New Heights',
	datePublished: '2026-01-25',
	speakable: new SpeakableSpecification(
		cssSelector: ['.headline', '.summary'],
	),
);

$json = JsonLdGenerator::SchemaToJson(schema: $article);
{
    "@context": "https://schema.org/",
    "@type": "Article",
    "headline": "Latest News: PHP Reaches New Heights",
    "datePublished": "2026-01-25",
    "speakable": {
        "@type": "SpeakableSpecification",
        "cssSelector": [
            ".headline",
            ".summary"
        ]
    }
}

TypeScript:

import { Article, JsonLdGenerator, SpeakableSpecification } from '@evabee/schema-org-json-ld';

const article = new Article({
  headline: 'Latest News: PHP Reaches New Heights',
  datePublished: '2026-01-25',
  speakable: new SpeakableSpecification({ cssSelector: ['.headline', '.summary'] }),
});

const json = JsonLdGenerator.schemaToJson(article);

Output is identical to the PHP JSON example above.


Subscription / Paywalled Content

Mark paywalled content using WebPageElement via the hasPart property on Article.

<?php

use EvaLok\SchemaOrgJsonLd\v1\JsonLdGenerator;
use EvaLok\SchemaOrgJsonLd\v1\Schema\Article;
use EvaLok\SchemaOrgJsonLd\v1\Schema\WebPageElement;

$article = new Article(
	headline: 'Premium: Advanced PHP Patterns Deep Dive',
	datePublished: '2026-02-01',
	isAccessibleForFree: false,
	hasPart: new WebPageElement(
		isAccessibleForFree: false,
		cssSelector: '.premium-content',
	),
);

$json = JsonLdGenerator::SchemaToJson(schema: $article);
{
    "@context": "https://schema.org/",
    "@type": "Article",
    "headline": "Premium: Advanced PHP Patterns Deep Dive",
    "datePublished": "2026-02-01",
    "isAccessibleForFree": false,
    "hasPart": {
        "@type": "WebPageElement",
        "isAccessibleForFree": false,
        "cssSelector": ".premium-content"
    }
}

TypeScript:

import { Article, JsonLdGenerator, WebPageElement } from '@evabee/schema-org-json-ld';

const article = new Article({
  headline: 'Premium: Advanced PHP Patterns Deep Dive',
  datePublished: '2026-02-01',
  isAccessibleForFree: false,
  hasPart: new WebPageElement({ isAccessibleForFree: false, cssSelector: '.premium-content' }),
});

const json = JsonLdGenerator.schemaToJson(article);

Output is identical to the PHP JSON example above.


Vacation Rental

<?php

use EvaLok\SchemaOrgJsonLd\v1\JsonLdGenerator;
use EvaLok\SchemaOrgJsonLd\v1\Schema\Accommodation;
use EvaLok\SchemaOrgJsonLd\v1\Schema\AggregateRating;
use EvaLok\SchemaOrgJsonLd\v1\Schema\BedDetails;
use EvaLok\SchemaOrgJsonLd\v1\Schema\PostalAddress;
use EvaLok\SchemaOrgJsonLd\v1\Schema\QuantitativeValue;
use EvaLok\SchemaOrgJsonLd\v1\Schema\VacationRental;

$rental = new VacationRental(
	name: 'Beachside Cottage',
	identifier: 'cottage-42',
	image: [
		'https://example.com/rentals/cottage-1.jpg',
		'https://example.com/rentals/cottage-2.jpg',
	],
	latitude: 36.8516,
	longitude: -75.9779,
	containsPlace: new Accommodation(
		occupancy: new QuantitativeValue(value: 4, unitCode: 'C62'),
		numberOfBedrooms: 2,
		numberOfBathroomsTotal: 1,
		bed: [
			new BedDetails(numberOfBeds: 1, typeOfBed: 'King'),
			new BedDetails(numberOfBeds: 2, typeOfBed: 'Twin'),
		],
	),
	address: new PostalAddress(
		streetAddress: '1 Ocean Drive',
		addressLocality: 'Virginia Beach',
		addressRegion: 'VA',
		postalCode: '23451',
		addressCountry: 'US',
	),
	aggregateRating: new AggregateRating(ratingValue: 4.8, reviewCount: 95, bestRating: 5),
	checkinTime: '15:00',
	checkoutTime: '11:00',
	description: 'A cozy cottage steps from the beach, perfect for a family getaway.',
);

$json = JsonLdGenerator::SchemaToJson(schema: $rental);
{
    "@context": "https://schema.org/",
    "@type": "VacationRental",
    "name": "Beachside Cottage",
    "identifier": "cottage-42",
    "image": [
        "https://example.com/rentals/cottage-1.jpg",
        "https://example.com/rentals/cottage-2.jpg"
    ],
    "latitude": 36.8516,
    "longitude": -75.9779,
    "containsPlace": {
        "@type": "Accommodation",
        "occupancy": {
            "@type": "QuantitativeValue",
            "value": 4,
            "unitCode": "C62"
        },
        "numberOfBedrooms": 2,
        "numberOfBathroomsTotal": 1,
        "bed": [
            {
                "@type": "BedDetails",
                "numberOfBeds": 1,
                "typeOfBed": "King"
            },
            {
                "@type": "BedDetails",
                "numberOfBeds": 2,
                "typeOfBed": "Twin"
            }
        ]
    },
    "address": {
        "@type": "PostalAddress",
        "streetAddress": "1 Ocean Drive",
        "addressLocality": "Virginia Beach",
        "addressRegion": "VA",
        "postalCode": "23451",
        "addressCountry": "US"
    },
    "aggregateRating": {
        "@type": "AggregateRating",
        "ratingValue": 4.8,
        "bestRating": 5,
        "reviewCount": 95
    },
    "checkinTime": "15:00",
    "checkoutTime": "11:00",
    "description": "A cozy cottage steps from the beach, perfect for a family getaway."
}

TypeScript:

import { Accommodation, BedDetails, JsonLdGenerator, QuantitativeValue, VacationRental } from '@evabee/schema-org-json-ld';

const rental = new VacationRental({
  name: 'Beachside Cottage',
  identifier: 'cottage-42',
  image: ['https://example.com/rentals/cottage-1.jpg', 'https://example.com/rentals/cottage-2.jpg'],
  latitude: 36.8516,
  longitude: -75.9779,
  containsPlace: new Accommodation({
    occupancy: new QuantitativeValue({ value: 4, unitCode: 'C62' }),
    numberOfBedrooms: 2,
    numberOfBathroomsTotal: 1,
    bed: [
      new BedDetails({ numberOfBeds: 1, typeOfBed: 'King' }),
      new BedDetails({ numberOfBeds: 2, typeOfBed: 'Twin' }),
    ],
  }),
});

const json = JsonLdGenerator.schemaToJson(rental);

Output is identical to the PHP JSON example above.


Video

<?php

use EvaLok\SchemaOrgJsonLd\v1\JsonLdGenerator;
use EvaLok\SchemaOrgJsonLd\v1\Schema\Clip;
use EvaLok\SchemaOrgJsonLd\v1\Schema\InteractionCounter;
use EvaLok\SchemaOrgJsonLd\v1\Schema\VideoObject;

$video = new VideoObject(
	name: 'Getting Started with PHP 8.3',
	thumbnailUrl: [
		'https://example.com/thumbnails/php83-tutorial-1x1.jpg',
		'https://example.com/thumbnails/php83-tutorial-16x9.jpg',
	],
	uploadDate: '2026-01-10',
	description: 'A comprehensive introduction to the new features in PHP 8.3.',
	contentUrl: 'https://example.com/videos/php83-tutorial.mp4',
	embedUrl: 'https://example.com/embed/php83-tutorial',
	duration: 'PT22M30S',
	expires: '2027-01-10',
	regionsAllowed: 'US,CA,GB',
	interactionStatistic: new InteractionCounter(interactionType: 'WatchAction', userInteractionCount: 45000),
	hasPart: [
		new Clip(name: 'Introduction', startOffset: 0, endOffset: 120, url: 'https://example.com/videos/php83-tutorial#intro'),
	],
);

$json = JsonLdGenerator::SchemaToJson(schema: $video);
{
    "@context": "https://schema.org/",
    "@type": "VideoObject",
    "name": "Getting Started with PHP 8.3",
    "thumbnailUrl": [
        "https://example.com/thumbnails/php83-tutorial-1x1.jpg",
        "https://example.com/thumbnails/php83-tutorial-16x9.jpg"
    ],
    "uploadDate": "2026-01-10",
    "description": "A comprehensive introduction to the new features in PHP 8.3.",
    "contentUrl": "https://example.com/videos/php83-tutorial.mp4",
    "embedUrl": "https://example.com/embed/php83-tutorial",
    "duration": "PT22M30S",
    "expires": "2027-01-10",
    "regionsAllowed": "US,CA,GB",
    "interactionStatistic": {
        "@type": "InteractionCounter",
        "interactionType": "WatchAction",
        "userInteractionCount": 45000
    },
    "hasPart": [
        {
            "@type": "Clip",
            "name": "Introduction",
            "startOffset": 0,
            "url": "https://example.com/videos/php83-tutorial#intro",
            "endOffset": 120
        }
    ]
}

TypeScript:

import { JsonLdGenerator, VideoObject } from '@evabee/schema-org-json-ld';

const video = new VideoObject({
  name: 'Getting Started with PHP 8.3',
  uploadDate: '2026-01-10',
  thumbnailUrl: ['https://example.com/thumbnails/php83-tutorial-1x1.jpg'],
});

const json = JsonLdGenerator.schemaToJson(video);

Output is identical to the PHP JSON example above.

Multiple Schemas per Page (@graph)

When a page contains multiple rich result entities (for example an Article and a BreadcrumbList), you can combine them into a single JSON-LD block using @graph.

<?php

use EvaLok\SchemaOrgJsonLd\v1\JsonLdGenerator;
use EvaLok\SchemaOrgJsonLd\v1\Schema\Article;
use EvaLok\SchemaOrgJsonLd\v1\Schema\BreadcrumbList;
use EvaLok\SchemaOrgJsonLd\v1\Schema\ListItem;

$article = new Article(
	headline: 'How to Bake Sourdough Bread',
);

$breadcrumb = new BreadcrumbList(
	itemListElement: [
		new ListItem(position: 1, name: 'Recipes', item: 'https://example.com/recipes'),
		new ListItem(position: 2, name: 'Bread', item: 'https://example.com/recipes/bread'),
	],
);

$json = JsonLdGenerator::SchemasToJson($article, $breadcrumb);
{
    "@context": "https://schema.org/",
    "@graph": [
        {
            "@type": "Article",
            "headline": "How to Bake Sourdough Bread"
        },
        {
            "@type": "BreadcrumbList",
            "itemListElement": [
                {
                    "@type": "ListItem",
                    "position": 1,
                    "name": "Recipes",
                    "item": "https://example.com/recipes"
                },
                {
                    "@type": "ListItem",
                    "position": 2,
                    "name": "Bread",
                    "item": "https://example.com/recipes/bread"
                }
            ]
        }
    ]
}

API Reference

PHP: JsonLdGenerator::SchemaToJson(TypedSchema $schema): string

Serializes any schema object to a JSON-LD string ready to embed in HTML.

$json = JsonLdGenerator::SchemaToJson(schema: $mySchema);
// Embed as: <script type="application/ld+json"><?= $json ?></script>

Behaviour:

  • Automatically adds @context (https://schema.org/) and @type (from the class constant).
  • A_SCHEMA_TYPE can be either a string ('Product') or an array of strings (['MathSolver', 'LearningResource']).
  • Skips null properties — only set properties are included in the output.
  • Recursively serializes nested TypedSchema instances.
  • Backed string enums (e.g. ItemAvailability, OfferItemCondition, EventStatusType) are automatically serialized to their .value (the full schema.org URL).
  • Arrays of schema objects and primitives are both handled correctly.

TypeScript: JsonLdGenerator.schemaToJson(schema: TypedSchema): string

TypeScript uses the same serialization behavior with a lowercase schemaToJson method name:

const json = JsonLdGenerator.schemaToJson(mySchema);

TypeScript: JsonLdGenerator.schemasToJson(...schemas: TypedSchema[]): string

Use this variant to generate an @graph payload from multiple schema objects:

const json = JsonLdGenerator.schemasToJson(article, breadcrumb);

TypedSchema (abstract base class)

All schema classes extend TypedSchema.

  • PHP uses public const A_SCHEMA_TYPE = 'TypeName';
  • TypeScript uses static readonly schemaType = 'TypeName';

The only requirement is that each class defines the schema type constant/property:

public const A_SCHEMA_TYPE = 'TypeName'; // e.g. 'Product', 'Article'

For schema.org properties that use names that are not valid language identifiers (for example mathExpression-input), define a property map:

public const PROPERTY_MAP = [
	'mathExpressionInput' => 'mathExpression-input',
];
static readonly propertyMap: Record<string, string> = {
  mathExpressionInput: 'mathExpression-input',
};

Schema classes use constructor promotion — all data is passed via the constructor and stored as public properties. No methods are needed beyond the constructor.


Testing

# PHP
composer run test-unit
composer run cs-fix
composer run cs-check

# TypeScript
npm run test       # Run Vitest tests
npm run build      # Build ESM/CJS
npx biome check    # Lint

See the php/test/unit and ts/test directories for the full test suites.


Known Validator Limitations

When validating JSON-LD output with third-party validators (such as the Adobe Structured Data Validator), you may encounter warnings for certain properties. These are validator limitations, not library bugs — the generated output is valid schema.org JSON-LD and passes Google's Rich Results Test.

datePublished warnings

The following types may trigger a datePublished warning in some validators, despite datePublished being a valid schema.org property inherited from CreativeWork:

  • MobileApplication
  • Movie
  • VacationRental

Recipe optional property warnings

These valid schema.org properties on Recipe may be flagged as "unsupported" by some validators:

  • expires
  • hasPart
  • publication
  • ineligibleRegion
  • interactionStatistic

These properties are defined on schema.org and are correctly serialized by this library. The warnings come from validators that maintain an incomplete allowlist of properties per type.


Contributing

Contributions are welcome! Please:

  1. Fork the repository and create a feature branch.
  2. Add or update schema classes in php/src/v1/Schema/ (PHP) or ts/src/schema/ (TypeScript).
  3. Write tests in php/test/unit/ (PHP) or ts/test/schema/ (TypeScript).
  4. Run composer run cs-fix and composer run test-unit for PHP changes.
  5. Run npm run test, npm run build, and npx biome check for TypeScript changes.
  6. For TypeScript schema additions, follow the options-object constructor pattern and update barrel exports in ts/src/index.ts.
  7. Open a pull request with a clear description of the change.

When adding a new schema type, follow the existing language-specific patterns: PHP classes extend TypedSchema and set A_SCHEMA_TYPE; TypeScript classes extend TypedSchema, set schemaType, and use options-object constructors.


License

MIT — see LICENSE.

About

library for generating Google-compatible json-ld rich results

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

 
 
 

Contributors