Dummy JSON CLI is cli tool for Dummy JSON by Matt Sweetman. It extends the default cli proposed by Dummy JSON to enable the use of custom data and custom helpers directly from the cli.
npm install dummy-json-cli -g
Basic usage
generatejson template.hbs
Save to file
generatejson template.hbs -o output.json
Extra help is available
generatejson -h
Based on the template filepath, the script will automatically lookup for a JSON custom data file (template name.data.json) and a JS module that exports custom helpers (template name.helpers.js).
Look at sample.hbs, sample.data.json, sample.helpers.js
- Dummy JSON Generator documentation
- HBS Templates documentation
See Dummy JSON Generator documentation for default helpers
const myMockdata = {
animals: ['fox', 'badger', 'crow']
};
const template = '{{#randomItem animals}}';
const result = dummyjson.parse(template, { mockdata: myMockdata }); // Returns one of "fox", "badger" or "crow"
You can feed your template with custom data using a JSON file (should be an object with each key as the variable name).
Either create a file with same name as the template and .data.json as extenion or use -d option to specify the filepath.
See sample/sample.data.json
A global nbRepeat variable will be set in addition to your custom data. You can override it in your custom data or using -r option
You can add custom helpers by creating a JavaScript module.
Either create a file with same name as the template and .helpers.js as extenion or use -f option to specify the filepath.