A lightweight, zero-dependency TypeScript library to effortlessly generate JSON-LD structured data for SEO purposes.
jsonld-easy
simplifies the process of creating schema.org
compliant JSON-LD markup. Instead of manually crafting complex JSON objects, you can use simple helper functions to generate the structured data your website needs to improve its search engine visibility.
npm install jsonld-easy
# or
yarn add jsonld-easy
# or
pnpm add jsonld-easy
The library provides preset functions for common schema types.
- Import a preset function (e.g.,
article
) and thetoScriptTag
helper. - Call the preset function with your data to generate the JSON-LD object.
- Use
toScriptTag
to wrap the object in a<script>
tag, ready to be injected into your HTML.
import { article, toScriptTag } from 'jsonld-easy';
const articleData = {
headline: 'My Awesome Article',
image: 'https://example.com/image.jpg',
authorName: 'John Doe',
datePublished: '2025-01-20',
publisherName: 'My Awesome Website',
};
const articleJsonLd = article(articleData);
// To get the raw JSON-LD object:
console.log(articleJsonLd);
// To get the full <script> tag:
const scriptTag = toScriptTag(articleJsonLd);
console.log(scriptTag);
/*
<script type="application/ld+json">{"@context":"https://schema.org","@type":"Article",...}</script>
*/
article(input: ArticleInput)
breadcrumb(items: BreadcrumbListItem[])
faqPage(input: FAQPageInput)
image(input: ImageObjectInput)
localBusiness(input: LocalBusinessInput)
product(input: ProductInput)
website(input: WebSiteInput)
You can inspect the function signatures or the src/presets
directory for details on the required input for each preset.
To build the project locally, clone the repository and run:
npm install
npm run build
This will compile the TypeScript source into the dist
directory.
Contributions are welcome! Please feel free to open an issue or submit a pull request.