Registry / database / wp-json-schemas

wp-json-schemas

JSON →
library4.70.1jsnpmunverified

Provides well-documented JSON schemas for WordPress PHP objects (like WP_Post, WP_Term, WP_User) and REST API responses (e.g., /wp/v2/posts). Version 4.70.1, updated for WordPress 7.0. Maintained by John Blackbourn; schemas also generate TypeScript definitions in the companion wp-types package. Differentiators: comprehensive, hand-maintained schemas covering both PHP objects and REST endpoints, with regular updates aligned to WordPress core releases.

npm install wp-json-schemas
INSTALL
IMPORT
SIG · WP-JSON-SCHEMAS
W
wp-json-schemas
databasejavascriptv4.70.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

WP_Post
import { WP_Post } from 'wp-json-schemas'
const WP_Post = require('wp-json-schemas')
ESM-only; no default export.
WP_REST_API_Post
import { WP_REST_API_Post } from 'wp-json-schemas'
import WP_REST_API_Post from 'wp-json-schemas'
Styled after the REST API route response; correct import is named.
WP_User
import { WP_User } from 'wp-json-schemas'
import { User } from 'wp-json-schemas'
Precise naming matches WordPress internal class; avoid generic names.

Validates a WordPress post object against the WP_Post JSON schema using Ajv, showing how to import schemas and use them for validation.

import { WP_Post, WP_REST_API_Posts } from 'wp-json-schemas'; // Example: validate a WP_Post object using a JSON schema validator like ajv import Ajv from 'ajv'; const ajv = new Ajv(); const validatePost = ajv.compile(WP_Post); const postData = { ID: 1, post_author: '1', post_date: '2023-01-01 00:00:00', post_content: 'Hello world', post_title: 'Hello', post_status: 'publish', post_type: 'post', // ... other fields }; const valid = validatePost(postData); if (!valid) { console.error(validatePost.errors); } else { console.log('Post data is valid against WP_Post schema'); }
Debug
Known issues
gotchaSchemas reflect WordPress 7.0, not the latest WordPress version. Avoid relying on fields that may have been added in later releases.
fix
Check the WordPress version compatibility matrix; update the package when WordPress is upgraded.
affects: >=4.70.0
gotchaSome REST API schemas are incomplete (marked 'Todo' in README). Using a 'Todo' schema may lead to validation errors or missing fields.
fix
Check the README for the list of pending schemas and avoid relying on those endpoints for validation.
affects: >=4.0.0
breakingVersion 4.x is ESM-only. Using CommonJS require() will fail.
fix
Use ES module imports (import ... from 'wp-json-schemas') or switch to version 3.x if CJS is required.
affects: >=4.0.0
Errors
Common errors & fixes
Cannot find module 'wp-json-schemas'
Package not installed or incorrect import path.
fix
npm install wp-json-schemas@4.70.1
SyntaxError: Unexpected token 'export'
Using CommonJS require() on an ESM-only package (v4+).
fix
Use ES module import syntax or downgrade to version 3.x with npm install wp-json-schemas@3
Property 'post_author' is missing in type '{}'
TypeScript strict mode; attempting to use empty object where a WP_Post is expected.
fix
Provide all required properties as defined in the schema, or use Partial<WP_Post> for optional fields.
Upgrade
Version history
4.70.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
29 hits · last 30 days
node
22
Meta
2
OpenAI (training)
1
Resources