{"id":49756,"library":"wp-json-schemas","title":"wp-json-schemas","description":"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.","status":"active","version":"4.70.1","language":"javascript","source_language":"en","source_url":"https://github.com/johnbillion/wp-json-schemas","tags":["javascript","schemas","wordpress"],"install":[{"cmd":"npm install wp-json-schemas","lang":"bash","label":"npm"},{"cmd":"yarn add wp-json-schemas","lang":"bash","label":"yarn"},{"cmd":"pnpm add wp-json-schemas","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"ESM-only; no default export.","wrong":"const WP_Post = require('wp-json-schemas')","symbol":"WP_Post","correct":"import { WP_Post } from 'wp-json-schemas'"},{"note":"Styled after the REST API route response; correct import is named.","wrong":"import WP_REST_API_Post from 'wp-json-schemas'","symbol":"WP_REST_API_Post","correct":"import { WP_REST_API_Post } from 'wp-json-schemas'"},{"note":"Precise naming matches WordPress internal class; avoid generic names.","wrong":"import { User } from 'wp-json-schemas'","symbol":"WP_User","correct":"import { WP_User } from 'wp-json-schemas'"}],"quickstart":{"code":"import { WP_Post, WP_REST_API_Posts } from 'wp-json-schemas';\n\n// Example: validate a WP_Post object using a JSON schema validator like ajv\nimport Ajv from 'ajv';\n\nconst ajv = new Ajv();\nconst validatePost = ajv.compile(WP_Post);\n\nconst postData = {\n  ID: 1,\n  post_author: '1',\n  post_date: '2023-01-01 00:00:00',\n  post_content: 'Hello world',\n  post_title: 'Hello',\n  post_status: 'publish',\n  post_type: 'post',\n  // ... other fields\n};\n\nconst valid = validatePost(postData);\nif (!valid) {\n  console.error(validatePost.errors);\n} else {\n  console.log('Post data is valid against WP_Post schema');\n}","lang":"typescript","description":"Validates a WordPress post object against the WP_Post JSON schema using Ajv, showing how to import schemas and use them for validation."},"warnings":[{"fix":"Check the WordPress version compatibility matrix; update the package when WordPress is upgraded.","message":"Schemas reflect WordPress 7.0, not the latest WordPress version. Avoid relying on fields that may have been added in later releases.","severity":"gotcha","affected_versions":">=4.70.0"},{"fix":"Check the README for the list of pending schemas and avoid relying on those endpoints for validation.","message":"Some REST API schemas are incomplete (marked 'Todo' in README). Using a 'Todo' schema may lead to validation errors or missing fields.","severity":"gotcha","affected_versions":">=4.0.0"},{"fix":"Use ES module imports (import ... from 'wp-json-schemas') or switch to version 3.x if CJS is required.","message":"Version 4.x is ESM-only. Using CommonJS require() will fail.","severity":"breaking","affected_versions":">=4.0.0"}],"env_vars":null,"search_vec":"'/wp/v2/posts':27 '4.70.1':29 '7.0':33 'align':66 'also':39 'api':24 'blackbourn':37 'companion':45 'comprehens':51 'core':69 'cover':56 'definit':42 'differenti':50 'document':8 'e.g':26 'endpoint':62 'generat':40 'hand':53 'hand-maintain':52 'javascript':71 'john':36 'json':3,9 'like':15 'maintain':34,54 'object':14,59 'packag':49 'php':13,58 'post':17 'provid':5 'regular':64 'releas':70 'respons':25 'rest':23,61 'schema':4,10,38,55,72 'term':19 'type':48 'typescript':41 'updat':30,65 'user':21 'version':28 'well':7 'well-docu':6 'wordpress':12,32,68,73 'wp':2,16,18,20,47 'wp-json-schema':1 'wp-type':46","created_at":"2026-06-07T17:03:26.881092+00:00","updated_at":"2026-06-07T17:03:26.881092+00:00","problems":[{"fix":"npm install wp-json-schemas@4.70.1","cause":"Package not installed or incorrect import path.","error":"Cannot find module 'wp-json-schemas'"},{"fix":"Use ES module import syntax or downgrade to version 3.x with npm install wp-json-schemas@3","cause":"Using CommonJS require() on an ESM-only package (v4+).","error":"SyntaxError: Unexpected token 'export'"},{"fix":"Provide all required properties as defined in the schema, or use Partial<WP_Post> for optional fields.","cause":"TypeScript strict mode; attempting to use empty object where a WP_Post is expected.","error":"Property 'post_author' is missing in type '{}'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/johnbillion/wp-json-schemas","github":"https://github.com/johnbillion/wp-json-schemas","docs":null,"changelog":null,"pypi":null,"npm":"wp-json-schemas","openapi_spec":null,"status_page":null,"smithery":null,"categories":["database","devops"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}