Random Value Generators

Overview

Mockend random generator is extremely flexible. It provides all the building blocks to generate any value.

See Custom Data for ways to provide your own data.

Meta

_.items

Use this field to control how many items you want Mockend to create (default/max: 100). For example, to create 10 posts:

.mockend.json
{
  "Post": {
    "_": { "items": 10 }
  }
}

Primitives

string|string[]

Generates a random string.

.mockend.json
{ "title": { "string": {} }

Pick a random string.

.mockend.json
{
  "category": {
    "string": ["One", "Two"]
  }
}

int|int[]

Generates a random integer between min and max.

.mockend.json
{ "likes": { "int": { "min": 0, "max": 1000000 } } }

Pick a random integer in array.

.mockend.json
{
  "code": {
    "int": [100, 200, 300]
  }
}

boolean

Generates a random boolean.

.mockend.json
{ "isPublished": { "boolean": {} } }

Dates

dateTime

Generates a random RFC3339 (opens in a new tab) DateTime between min and max.

.mockend.json
{
  "createdAt: {
    "dateTime": {
      "min": "2010-01-01T00:00:00Z",
      "max": "2020-12-31T23:59:59Z"
    }
  }
}

Lorem ipsum

loremWord

Generates a random word.

.mockend.json
{
  "tag": {
    "loremWord": {}
  }
}

loremWords

Generates random words between minLength and maxLength.

.mockend.json
{
  "title": {
    "loremWords": { "minLength": 5, "maxLength": 20 }
  }
}

loremSentences

Generates random sentences between minLength and maxLength.

.mockend.json
{
  "longDescription": {
    "loremSentences": { "minLength": 100, "maxLength": 200 }
  }
}

loremParagraphs

Generates random paragraphs between minLength and maxLength.

.mockend.json
{
  "text": {
    "loremParagraphs": { "minLength": 200, "maxLength": 500 }
  }
}

Regexp

Generates a random string based on regular expression.

.mockend.json
{ "name": { "regexp": "[A-Z][a-z]{5,10}" } }

Examples

regexp generator is a powerful way to create any string. Here are some examples to get you started. Feel free to adapt them to suit your needs.

Pictures

.mockend.json
{
  "avatar": {
    "regexp": "https://i\\.pravatar\\.cc/150\\?u=[0-9]{5}"
  },
  "photo": {
    "regexp": "https://picsum\\.photos/seed/[0-9]{5}/1920/1080"
  }
}

Generates URLs to online services with a random seed ([0-9]{5} = 5 random numbers).

Names

.mockend.json
{ "firstName": { "regexp": "[A-Z][a-z]{5,10}" } }

Generates a random string starting with an uppercase letter and between 5 to 10 lowercase letters.

Emails

.mockend.json
{ "email": { "regexp": "[a-z]{5,10}@[a-z]{5}\\.[a-z]{2,3}" } }

Generates an email containing @ and with a domain of 2 or 3 letters.

Hex colors

.mockend.json
{ "color": { "regexp": "#[0-9A-F]{6}" } }

Generates an hex color.

Last updated on January 16, 2023