Last active
March 23, 2024 12:35
-
-
Save up1/b6b92e90be040507f16d566ee5c6232f to your computer and use it in GitHub Desktop.
Json Schema Faker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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