danibram / mocker-data-generator

A simplified way to generate masive mock data based on a schema, you can use the awesome fake/random data generators like (FakerJs, ChanceJs, CasualJs and RandExpJs)
https://danibram.github.io/mocker-data-generator/
MIT License
426 stars 45 forks source link

Output generated by Mocker is not JSON #101

Closed dalinwanglhtz closed 4 years ago

dalinwanglhtz commented 4 years ago

Hi Dani, recently I was playing around with mocker generator from my local machine. After getting everything up and running, I started generating some json data using your example code in your "code" section. I later realized that the keys in the JSON output (from running >node .js after compiled the ts file) doesn't have double quote around them. Strictly speaking that's not JSON.

See snippet below. As you can see the keys have no double quotes around them when they should. I've being looking back'n'forth but couldn't find any documentation on how include the double quotes to make them proper JSON. Your playground does seemed to return a proper JSON file. Not sure how you did it. Could you help me? { users: [ { firstName: 'Chanel', lastName: 'Marks', jobTitle: 'Internal Integration Representative', country: 'Costa Rica', createdAt: 2018-11-12T15:38:46.504Z, username: 'MarksCha3' }, { firstName: 'Josie', lastName: 'Herzog', jobTitle: 'Product Branding Agent', country: 'Portugal', createdAt: 2019-03-22T16:09:04.747Z, username: 'HerzoJos8' },

danibram commented 4 years ago

Hi, If you want to print JSON you should force that with JSON.stringify(YOUR_OBJECT), js file its diferente to json format, if you use a console log you are printing js code not in json format.

danibram commented 4 years ago

I want to clarify more that with a little bit of code:

const m = mocker()
/* your schemas here*/ 
    .build(function(err, data) {
        console.log(data) //Not JSON, JS
        console.log(JSON.stringify(data)) //JSON
    })

I think now its more clear. Thanks!