webroo / dummy-json

Generates random dummy JSON data in Node.js
MIT License
380 stars 61 forks source link

Random people index #3

Closed thiagomata closed 8 years ago

thiagomata commented 9 years ago

The people list always returns the same people. To be more random, as a search, may be useful create a way to make the personIndex be random. Something like:

{
  "people": [
    {{#repeat 2}}
    {
      "id": {{randomIndex}},
      "firstName": "{{firstName}}",
      "lastName": "{{lastName}}",
      "email": "{{email}}",
      "work": "{{company}}",
      "age": {{number 20 50}},
      "optedin": {{boolean}}
    }
    {{/repeat}}
  ]
}

Creating something like

{
  "people": [
    {
      "id": 71,
      "firstName": "Travis",
      "lastName": "Remus",
      "email": "travis.remus@keycast.com",
      "work": "Keycast",
      "age": 21,
      "optedin": true
    },
    {
      "id": 48,
      "firstName": "Raymond",
      "lastName": "Gamble",
      "email": "raymond.gamble@fastmart.com",
      "work": "FastMart",
      "age": 45,
      "optedin": false
    }
  ]
}
webroo commented 8 years ago

This is now the default mode of dummyjson. If you need the same data every time you can use a random seed https://github.com/webroo/dummy-json#seeded-random-data