Reputation: 325
I'm trying to populate a json file with some fake seed data for a User db collection: Here is how i'm writing to the json file: Generate json file
Here is what I get as output in the User.json file: User.json file
But this is what I get if I console.log(people) after the for loop:
[ { f_name: 'Destin',
l_name: 'Halvorson',
username: 'Mustafa.Nitzsche',
password: 'password' },
{ f_name: 'Giovani',
l_name: 'Weber',
username: 'Jodie.Frami25',
password: 'password' },
{ f_name: 'Zion',
l_name: 'Hermann',
username: 'Brain.Deckow',
password: 'password' },
{ f_name: 'Walker',
l_name: 'Donnelly',
username: 'Berniece14',
password: 'password' },
{ f_name: 'Stanton',
l_name: 'Rau',
username: 'Alysha18',
password: 'password' },
{ f_name: 'Alexandrea',
l_name: 'Emard',
username: 'Juvenal9',
password: 'password' },
{ f_name: 'Elta',
l_name: 'Bailey',
username: 'Foster.Mann',
password: 'password' },
{ f_name: 'Noemie',
l_name: 'Zboncak',
username: 'Guillermo45',
password: 'password' },
{ f_name: 'Elva',
l_name: 'Weissnat',
username: 'Willie_Koss',
password: 'password' },
{ f_name: 'Danny',
l_name: 'Dickinson',
username: 'Melyna_Herman87',
password: 'password' } ]
This btw is exactly what I want
I'm just curious about why it reverts back to each element being an "object"?
Any tips or answers would be awesome!
Upvotes: 0
Views: 1081
Reputation: 36
Use
JSON.stringify(object, replacer, space);
For your case I would:
JSON.stringify(people, null, '\t');
Source: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify
Upvotes: 2