Registry / devops / json-to-json-schema

json-to-json-schema

JSON →
library0.0.4jsnpmunverified

Convert a JSON value into a JSON Schema that describes its structure. This library infers types (string, number, boolean, array, object, null) and generates a basic JSON Schema draft-04 compatible output. Version 0.0.4 is the latest release, with no further updates since 2016. It is a lightweight utility suitable for quick schema generation, but lacks support for advanced features like pattern validation, enums, or custom keywords. Alternative libraries like jsonschema or ajv provide more comprehensive schema handling.

npm install json-to-json-schema
INSTALL
IMPORT
SIG · JSON-TO-JSON-SCHEM
J
json-to-json-schema
devopsjavascriptv0.0.4
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.

convert
import { convert } from 'json-schema-from-json';
import convert from 'json-schema-from-json';
The package exports a named export 'convert', not a default. Note the package name in the import is 'json-schema-from-json', which is different from the npm package name 'json-to-json-schema' due to an error in the README.
convert
const { convert } = require('json-schema-from-json');
const convert = require('json-schema-from-json');
CommonJS destructuring is required because 'convert' is a named export.
JSONToJSONSchema
const schema = JSONToJSONSchema.convert(json);
const schema = JSONToJSONSchema(json);
In browser UMD builds, the global object is 'JSONToJSONSchema' and the function is under 'convert' property.

Converts a sample JSON object into a JSON Schema showing inferred types and required fields.

import { convert } from 'json-schema-from-json'; const json = { name: 'Alice', age: 30, active: true, tags: ['admin', 'user'], address: null }; const schema = convert(json); console.log(JSON.stringify(schema, null, 2)); // Output: // { // "type": "object", // "properties": { // "name": { "type": "string" }, // "age": { "type": "number" }, // "active": { "type": "boolean" }, // "tags": { "type": "array", "items": { "type": "string" } }, // "address": { "type": "null" } // }, // "required": ["name", "age", "active", "tags", "address"] // }
Debug
Known issues
breakingThe import path in the README is incorrect: 'json-schema-from-json' does not match the package name 'json-to-json-schema'. Using the wrong import will result in a module not found error.
fix
Install the package as 'json-to-json-schema' but import using the name 'json-schema-from-json' (as per the README). Alternatively, check actual exports via the installed package.
affects: >=0.0.0
deprecatedPackage has not been updated since 2016. It uses outdated dependencies (Babel 5) and is not compatible with modern JavaScript tooling.
fix
Consider using an actively maintained alternative like 'jsonschema' or 'generate-schema'.
affects: 0.0.4
gotchaThe package does not handle arrays with mixed types or nested objects consistently. All items in an array share the same type, which may not reflect the actual data.
fix
Manually validate generated schemas for complex data structures.
affects: >=0.0.0
Errors
Common errors & fixes
Error: Cannot find module 'json-schema-from-json'
Trying to import using the name given in the README, which is different from the installed package name.
fix
Install 'json-to-json-schema' and import using the same name: import { convert } from 'json-to-json-schema';
TypeError: convert is not a function
Attempting to import 'convert' as a default export instead of named export.
fix
Use named import: import { convert } from 'json-to-json-schema';
TypeError: JSONToJSONSchema is not a function
In browser, using the global 'JSONToJSONSchema' as a function directly, but it is an object with a 'convert' method.
fix
Use JSONToJSONSchema.convert(json) instead.
Upgrade
Version history
0.0.4latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
json-to-json-schema — npm install json-to-json-schema · libregistry