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.
FunctionJson
✓ import { FunctionJson } from 'function-json-schema'
✗ const FunctionJson = require('function-json-schema')
TypeScript type; ESM import only.
functionJsonSchema
✓ import { functionJsonSchema } from 'function-json-schema'
✗ import { FunctionJsonSchema } from 'function-json-schema'
Case-sensitive named export.
coerceFunctionJsonSchema
✓ import { coerceFunctionJsonSchema } from 'function-json-schema'
✗ import { coerceFunctionJsonSchema } from 'function-json-schema/coerce'
Directly from package root.
Shows both strict validation and coercive validation of a function JSON schema.
import { functionJsonSchema, coerceFunctionJsonSchema } from 'function-json-schema';
const rawSchema = {
name: 'getWeather',
description: 'Gets weather',
parameters: { type: 'object', properties: { location: { type: 'string', description: 'city' } }, required: ['location'] },
returns: { type: 'object', properties: { temp: { type: 'number', description: 'temp' } } },
};
// Strict validation
const result = functionJsonSchema.safeParse(rawSchema);
console.log(result.success); // true
// Coercive validation (fills defaults, coerces types)
const coerced = coerceFunctionJsonSchema(rawSchema);
console.log(coerced); // validated & modified schema
Errors
Common errors & fixes
TypeError: Cannot read properties of undefined (reading 'safeParse')
Missing import of functionJsonSchema or using default import incorrectly.
fixUse named import: import { functionJsonSchema } from 'function-json-schema'; Uncaught TypeError: coerceFunctionJsonSchema is not a function
Package not installed or wrong import path.
fixRun npm install function-json-schema and use named import.
TypeError: object is not a valid value for type 'object'
Provided schema does not match the FunctionJson type due to missing required fields (description, returns).
fixEnsure schema includes all required fields: name, description, parameters, returns.
Audit
Dependencies
zodrequiredRuntime dependency for schema validation and type inference