Skip to main content

JSON

You can export the data generated by schemas or any type of data to json format

const userSchema = chaca.schema({
id: schemas.id.uuid(),
username: schemas.internet.userName(),
image: { type: schemas.image.people(), posibleNull: 50 },
posts: {
type: schemas.id.uuid(),
isArray: {
min: 1,
max: 5,
},
},
})

await userSchema.generateAndExport({
filaName: 'data',
format: 'json',
location: 'folder',
})

For example, if we have this schema, we generate 5 documents and export them in json format, we will obtain the following result

[
{
"id": "18c91452-3db6-4051-8186-49aa2a260542",
"username": "Asher237",
"image": "https://images.unsplash.com/photo-1464746133101-a2c3f88e0dd9?crop=entropy&cs=tinysrgb&fm=jpg&ixid=MnwzNTM2NjZ8MHwxfHNlYXJjaHw0MXx8cGVvcGxlfGVufDB8fHx8MTY2Njk3MDgzMw&ixlib=rb-4.0.3&q=80",
"posts": ["e59b58d0-9e19-445e-b4ac-0831ab8295a0"]
},
{
"id": "3734b57d-8aa4-4584-b381-8ad1d2c095ad",
"username": "Ezekiel372",
"image": "https://images.pexels.com/photos/1417255/pexels-photo-1417255.jpeg",
"posts": [
"1a14185c-b2b5-42a1-9875-a50781e0e049",
"a35eab78-6938-4522-b89e-bcbb7adac9bd",
"a89309cb-2861-4243-9e86-6e8c962e977b"
]
},
{
"id": "6763a16a-4c17-43a9-989e-cb2067250014",
"username": "Eleanor430",
"image": "https://images.pexels.com/photos/18495/pexels-photo.jpg",
"posts": [
"6e1653c9-a235-4977-b47b-38c7ac583225",
"434c4b5c-02c9-4120-a6e5-6d8615c195c0",
"8bb471ac-2e96-493e-9357-10d706c00655",
"bdb363e3-5a25-4bad-910a-a17920167b0a"
]
},
{
"id": "54cebc5c-b9c4-4329-b4c5-7aa48a3b199a",
"username": "Nolan_",
"image": "https://images.unsplash.com/photo-1524601500432-1e1a4c71d692?crop=entropy&cs=tinysrgb&fm=jpg&ixid=MnwzNTM2NjZ8MHwxfHNlYXJjaHw2Mnx8cGVvcGxlfGVufDB8fHx8MTY2Njk3MDgzMw&ixlib=rb-4.0.3&q=80",
"posts": [
"7a94657e-bc00-4052-ade6-4ed54cc340dc",
"d32c218a-3cd2-4cac-8324-cb7988216a6a",
"53a2390e-862c-434c-b14a-0897cdb2dddc"
]
},
{
"id": "1c211b02-ab00-405c-9db1-569d803bed61",
"username": "Matthew446",
"image": null,
"posts": [
"b489023c-7771-45da-9d6e-35e8753e775d",
"15408eab-1c93-4709-8028-7be66b5701d6",
"6778e034-788d-4309-829c-905bc9d04dba",
"c7060016-3567-41b5-a278-b8db64eb9846"
]
}
]