@mdxld/json
Bi-directional conversion to JSON, JSON-LD, JSON Schema, OpenAPI, MCP, and GraphQL
@mdxld/json
Convert objects to multiple JSON-based formats: plain JSON, JSON-LD (linked data), JSON Schema (validation), OpenAPI (API docs), MCP (AI tools), and GraphQL SDL.
Installation
Quick Start
API Reference
toJSON / fromJSON
Basic JSON serialization with options.
toJSONLD / fromJSONLD
Convert to/from JSON-LD with Schema.org context.
Example:
Output:
toJSONSchema
Generate JSON Schema for validation.
Example:
Output:
toOpenAPI
Generate OpenAPI specification from API endpoints.
Example:
toMCP
Generate MCP (Model Context Protocol) tool definitions for AI.
Example:
Output:
toGraphQL
Generate GraphQL SDL from type definitions.
Example:
Output:
Schema.org Type Inference
toJSONLD automatically infers Schema.org types from object shapes:
| Object Shape | Inferred @type |
|---|---|
Has email + name | Person or Organization |
Has address | Place or PostalAddress |
Has startDate | Event |
Has ingredients + instructions | Recipe |
Has headline + author | Article |
Has properties + actions | Class |
Property Mapping
Common properties are automatically mapped to Schema.org:
| Object Key | Schema.org Property |
|---|---|
phone | telephone |
address.street | streetAddress |
address.city | addressLocality |
address.state | addressRegion |
address.zip | postalCode |
Use Cases
SEO Structured Data
API Documentation
Runtime Validation
AI Tool Definitions
Related Packages
| Package | Description |
|---|---|
@mdxld/jsonld | Full JSON-LD processing (expand, compact, frame) |
@mdxld/typescript | TypeScript types and Zod schemas |
@mdxui/json | Styled JSON output |