{"id":22374540,"url":"https://github.com/kevcui/fakergen","last_synced_at":"2025-10-17T12:36:41.393Z","repository":{"id":132197958,"uuid":"284255797","full_name":"KevCui/Fakergen","owner":"KevCui","description":":tophat: Generate JSON/YAML/XML... mock data with a structured template","archived":false,"fork":false,"pushed_at":"2021-05-10T11:13:43.000Z","size":25,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-16T22:05:21.058Z","etag":null,"topics":["data-generator","devops","devops-tools","fake-generator","faker","faker-generator","faker-providers","json","json-data","json-generator","json-schema","json-template","mock","mock-data","mock-json","testing","testing-tool","testing-tools","xml","yaml"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/KevCui.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-08-01T12:29:37.000Z","updated_at":"2025-10-03T22:10:41.000Z","dependencies_parsed_at":null,"dependency_job_id":"2383ad61-8437-4bfb-81d1-cd868d211419","html_url":"https://github.com/KevCui/Fakergen","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/KevCui/Fakergen","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KevCui%2FFakergen","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KevCui%2FFakergen/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KevCui%2FFakergen/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KevCui%2FFakergen/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/KevCui","download_url":"https://codeload.github.com/KevCui/Fakergen/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KevCui%2FFakergen/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279290003,"owners_count":26141131,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-17T02:00:07.504Z","response_time":56,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["data-generator","devops","devops-tools","fake-generator","faker","faker-generator","faker-providers","json","json-data","json-generator","json-schema","json-template","mock","mock-data","mock-json","testing","testing-tool","testing-tools","xml","yaml"],"created_at":"2024-12-04T21:17:26.323Z","updated_at":"2025-10-17T12:36:41.386Z","avatar_url":"https://github.com/KevCui.png","language":"Python","readme":"# Fakergen\n\n\u003e Generate JSON/YAML/XML... mock data with a structured template using Faker under the hood.\n\n## Table of Contents\n\n- [Features](#features)\n- [Dependency](#dependency)\n- [Usage](#usage)\n  - [How to create a Faker template?](#how-to-create-a-faker-template)\n  - [How to create and use custom function?](#how-to-create-and-use-custom-function)\n  - [How to repeat certain elements?](#how-to-repeat-certain-elements)\n- [Credits](#credits)\n\n## Features\n\n- Human-readable syntax as template\n- Fully support Faker providers\n- Customizable extended functions\n- Support any file formats: JSON, YAML, XML...\n- CLI script, easy to be integrated into any CI process\n- Support seed value for generating same output data\n\n## Dependency\n\n```bash\n$ pip install Faker\n```\n\n## Usage\n\n```\nusage: fakergen.py [-h] [-q] [-s SEED] template\n\npositional arguments:\n  template              template file\n\noptional arguments:\n  -h, --help            show this help message and exit\n  -q, --quiet           be quiet, no error message\n  -s SEED, --seed SEED  set seed value\n```\n\n- Generate JSON data using default `./template.json`:\n\n```bash\n$ cat ./template.json\n[\n  {\n    \"product_number\": \"{{bothify(text='????-########', letters='ABCDE')}}\",\n    \"hostname\": \"{{hostname(2)}}\",\n    \"attributes\": [\n      {\n        \"text\": \"static text\",\n        \"ean\": \"{{ean13(leading_zero=False)}}\",\n        \"random_number\": {{pyint(min_value=1, max_value=999, step=1)}},\n        \"colors\": \"{{color_name()}} {{color_name()}}\",\n        \"custom_greeting\": \"{{greeting()}}\"\n      }\n    ]\n  }\n]\n\n$ ./fakergen.py template.json\n[\n  {\n    \"product_number\": \"CEAD-00367795\",\n    \"hostname\": \"lt-75.collins.rivera-riley.com\",\n    \"attributes\": [\n      {\n        \"text\": \"static text\",\n        \"ean\": \"7263776026664\",\n        \"random_number\": 65,\n        \"colors\": \"OldLace Tomato\",\n        \"custom_greeting\": \"Hi there\"\n      }\n    ]\n  }\n]\n```\n\n### How to create a Faker template?\n\nFaker template is basically a file with variables inside. As an example, `./template.json` shows briefly how a template looks like: Using `{{...}}` to surround Faker provider name or custom function name will indicate the function to be executed as a Faker provider or a python function.\n\nA list of Faker providers can be found [here](https://faker.readthedocs.io/en/stable/providers.html).\n\n### How to create and use custom function?\n\nThe preprepared `CustomProviders` class is located in `./customprovider.py`. Firstly, add a function inside this class. Then this custom function can be called from Faker template.\n\nCheckout `greeting()` function as an example.\n\n### How to repeat certain elements?\n\n- One solution is to generate a new JSON template with repeated elements. Using [jq](https://stedolan.github.io/jq/download/) can simply do the job. For example, repeat `attributes`:\n\n```bash\njq '.[].attributes += $el' --argjson el \"$(jq '.[].attributes' template.json)\" template.json \u003e newtemplate.json\n```\n\nIf more repeats are needed, `for` loop is helpful. For example, repeat `attributes` 5 times:\n\n```bash\nj=\"$(cat template.json)\"; for ((i=0;i\u003c5;i++)); do j=\"$(jq '.[].attributes += $el' --argjson el \"$(jq '.[].attributes' template.json)\" \u003c\u003c\u003c \"$j\")\"; done; echo \"$j\" \u003e newtemplate.json\n```\n\nTo generate YAML/XML template, similar to `jq`, [yq](https://github.com/kislyuk/yq) is recommended.\n\n## Credits\n\nInspired by [JSON Generator](https://www.json-generator.com/)\n\n---\n\n\u003ca href=\"https://www.buymeacoffee.com/kevcui\" target=\"_blank\"\u003e\u003cimg src=\"https://cdn.buymeacoffee.com/buttons/v2/default-orange.png\" alt=\"Buy Me A Coffee\" height=\"60px\" width=\"217px\"\u003e\u003c/a\u003e","funding_links":["https://www.buymeacoffee.com/kevcui"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkevcui%2Ffakergen","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkevcui%2Ffakergen","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkevcui%2Ffakergen/lists"}