json-schema-faker-cli provides a command-line interface (CLI) for the json-schema-faker library, enabling users to generate realistic mock data based on JSON schemas directly from the terminal without requiring programmatic JavaScript interaction. It is currently at version 5.0.6 and primarily serves as a utility for quick data generation. The tool allows specifying a JSON schema file, an optional output file, the number of items for array generation, and a separate options file (JS or JSON format) to customize the faker's behavior. While json-schema-faker itself is a library for programmatic use, this package differentiates itself by offering a shell-based workflow, making it ideal for scaffolding mock APIs, testing, or populating databases with dummy data through simple CLI commands. Its release cadence is generally tied to the underlying json-schema-faker library's evolution, offering a stable and straightforward interface.
npm install json-schema-faker-cliVerified import paths — ran on the pinned version, not inferred.
Demonstrates global installation, basic single object generation, array generation, and usage with an external CommonJS options file, outputting to stdout or a file, then cleans up.
Check the `package.json` for the exact `json-schema-faker` version range it depends on. If you require features or fixes from a newer `json-schema-faker` release, consider using `json-schema-faker` programmatically in your own script or waiting for an update to `json-schema-faker-cli` that updates its dependency.
If you want to skip the output file and array length but provide an options file, the correct syntax is `generate-json schema.json none none options.js`.
Ensure JavaScript options files use `module.exports = {...}`. For projects using ES Modules extensively, it's often simpler and more robust to use a `.json` options file for compatibility.For schemas generating large data or when generating multiple items, always specify an output file (`generate-json schema.json output.json`). Use `stdout` primarily for small, quick checks or when explicitly piping the output to another utility.
Install the package globally using `npm install -g json-schema-faker-cli` or execute the command via `npx` for a temporary run: `npx json-schema-faker-cli generate-json ...`
Validate your `schema.json` and `options.json` files using a linter or online JSON validator. Ensure they strictly adhere to JSON syntax rules. If using a JS options file, confirm it's valid CommonJS.
Ensure the array length argument is a valid positive integer. If you are skipping previous arguments, make sure to use `none` placeholders correctly. For example, `generate-json schema.json output.json 5` or `generate-json schema.json none 5 options.js`.