Jon Jon - 3 months ago 30x
jQuery Question

Generate JSON with Random Data

I"m using chance.js to help me generate some random data. It works really well, and I'd like to use this data to output random JSON objects.

Here's the structure I'm after:

"users": [
"Name": "John Smith",
"Fname": "John",
"Lname": "Smith",
"Email": "",


I have chance.js working in a jsFiddle, but I'm not sure how to output JSON data with the

$(function() {
$("div[data]").each(function() {
var data = $(this).attr("data");
var chance = new Chance(Math.Random);

The chance.js documentation is available here:


Here is an array of 10 random objects:

var arr = new Array(10).fill().map(function() {
    return {
        first: chance["first"](),
        last: chance["last"](),
        email: chance["email"](),
        city: chance["city"](),
        state: chance["state"](),

var json = JSON.stringify({ users: arr }); // as you asked for json
<script src=""></script>
<script src=""></script>