{"id":17730,"library":"json-schema-faker-cli","title":"JSON Schema Faker CLI","description":"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.","status":"active","version":"5.0.6","language":"javascript","source_language":"en","source_url":"https://github.com/oprogramador/json-schema-faker-cli","tags":["javascript","json","schema","fake","faker","cli","mock"],"install":[{"cmd":"npm install json-schema-faker-cli","lang":"bash","label":"npm"},{"cmd":"yarn add json-schema-faker-cli","lang":"bash","label":"yarn"},{"cmd":"pnpm add json-schema-faker-cli","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Core dependency; this package is a CLI wrapper for json-schema-faker. It dictates the mocking capabilities and underlying data generation logic.","package":"json-schema-faker","optional":false}],"imports":[{"note":"This package is a command-line interface tool and is not intended for programmatic import into JavaScript/TypeScript code. Its primary 'symbol' is the `generate-json` shell command, accessible after global installation or via `npx`.","wrong":"import { generateJson } from 'json-schema-faker-cli'","symbol":"generate-json","correct":"generate-json schema.json output.json"},{"note":"When providing a JavaScript options file to the CLI, it expects a CommonJS module (`module.exports`), not an ES Module (`export default`). The CLI performs the module loading internally.","wrong":"export default { minLength: 20 };","symbol":"Options file (JS)","correct":"// options.js\nmodule.exports = { minLength: 20 };"},{"note":"A plain JSON file can also be used for options. Ensure it contains valid JSON syntax (no comments, no trailing commas) as the CLI will parse it directly.","symbol":"Options file (JSON)","correct":"// options.json\n{ \"minLength\": 20 }"}],"quickstart":{"code":"npm install -g json-schema-faker-cli\n\n# Create a JSON schema file (e.g., schema.json)\ncat > schema.json <<EOF\n{\n  \"type\": \"object\",\n  \"properties\": {\n    \"id\": { \"type\": \"integer\", \"format\": \"uuid\" },\n    \"name\": { \"type\": \"string\", \"faker\": \"name.findName\" },\n    \"email\": { \"type\": \"string\", \"format\": \"email\" },\n    \"createdAt\": { \"type\": \"string\", \"format\": \"date-time\" }\n  },\n  \"required\": [\"id\", \"name\", \"email\"]\n}\nEOF\n\n# Create an optional JavaScript options file (e.g., options.js)\ncat > options.js <<EOF\nmodule.exports = {\n  minLength: 10,\n  failOnInvalidFormat: false,\n  random: () => 0.5 // Ensures consistent output for demo\n};\nEOF\n\necho \"\\n--- Generating a single object to stdout ---\"\ngenerate-json schema.json\n\necho \"\\n--- Generating a single object to 'output.json' ---\"\ngenerate-json schema.json output.json\n\necho \"\\n--- Generating an array of 3 objects to 'output-array.json' ---\"\ngenerate-json schema.json output-array.json 3\n\necho \"\\n--- Generating with custom options from 'options.js' to 'output-with-options.json' ---\"\ngenerate-json schema.json output-with-options.json none options.js\n\n# Clean up generated files\nrm schema.json output.json output-array.json output-with-options.json options.js\n","lang":"bash","description":"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."},"warnings":[{"fix":"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.","message":"This CLI currently depends on a specific release candidate range of `json-schema-faker` (`^0.5.0-rc.21`). This means it may not be compatible with newer major versions of the underlying `json-schema-faker` library (e.g., `0.6.x` or `0.7.x`) which can introduce breaking changes to options, faker providers, or schema interpretation. Users should ensure their expectations align with the features and behaviors of the `0.5.x-rc` series.","severity":"breaking","affected_versions":">=5.0.0"},{"fix":"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`.","message":"When skipping optional parameters to provide a later one (e.g., providing an options file but no output file), you must explicitly use `none` as a placeholder for each skipped parameter. Forgetting this will cause subsequent parameters to be misinterpreted by the CLI.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"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.","message":"The options file can be either a plain JSON file or a CommonJS JavaScript file (`module.exports = { ... }`). If it's a JavaScript file, it must conform to CommonJS syntax, not ES Module (`export default { ... }`) syntax, as Node.js in the context of this CLI will load it as CommonJS.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"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.","message":"Outputting generated JSON to `stdout` (by omitting the output file path) is useful for piping to other commands, but can be problematic if the schema generates a very large JSON output, potentially flooding the terminal, causing performance issues, or making inspection difficult.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-23T00:00:00.000Z","next_check":"2026-07-22T00:00:00.000Z","problems":[{"fix":"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 ...`","cause":"The `json-schema-faker-cli` package has not been installed globally, or the `npm` global bin directory is not included in your system's PATH environment variable.","error":"command not found: generate-json"},{"fix":"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.","cause":"The provided schema file (`schema.json`) or options file (`options.json`) contains malformed JSON, such as incorrect syntax, comments, or trailing commas, preventing it from being parsed correctly.","error":"SyntaxError: Unexpected token '{' in JSON at position 1 (or similar JSON parsing error)"},{"fix":"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`.","cause":"The array length parameter (the third argument) was provided with a non-numeric value, or it was incorrectly interpreted as `undefined` due to misplacement when skipping preceding optional parameters.","error":"Error: Not a number: undefined (or similar type error related to array length argument)"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}