Skip to content

Instantly share code, notes, and snippets.

@up1
Last active March 23, 2024 12:35
Show Gist options
  • Save up1/b6b92e90be040507f16d566ee5c6232f to your computer and use it in GitHub Desktop.
Save up1/b6b92e90be040507f16d566ee5c6232f to your computer and use it in GitHub Desktop.
Json Schema Faker
$node sample.js
{
"id": 32844286,
"username": "labore",
"email": "ad in enim consequat nisi",
"firstName": "Ut nisi",
"lastName": "cillum aute est mollit minim",
"gender": "female",
"image": "velit proident commodo do",
"token": "elit dolore"
}
const jsf = require('json-schema-faker');
const schema = {
"type": "object",
"properties": {
"id": {
"type": "integer"
},
"username": {
"type": "string",
"faker": "internet.userName"
},
"email": {
"type": "string",
"faker": "internet.email"
},
"firstName": {
"type": "string",
"faker": "name.firstName"
},
"lastName": {
"type": "string",
"faker": "name.lastName"
},
"gender": {
"type": "string",
"enum": ["male", "female"]
},
"image": {
"type": "string",
"faker": "image.imageUrl"
},
"token": {
"type": "string",
"faker": "random.uuid"
}
},
"required": ["id", "username", "email", "firstName", "lastName", "gender", "image", "token"]
};
jsf.resolve(schema).then(sample => {
console.log(JSON.stringify(sample, null, 2));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment