Token Replacement

Add dynamic, random data to your JSON responses with simple tokens

When building and testing applications, you often need realistic data that looks and feels like what your API will return in production. Imagine you're developing a user profile page - you could hardcode test data like "John Doe" and "test@example.com", but what if you need:

  • Different data on each API call to test how your UI handles various inputs
  • Realistic-looking names and emails that match your production data patterns
  • Random numbers within specific ranges for testing edge cases
  • Dynamic dates that stay relevant without manual updates

This is where SuperBins tokens come in. By adding simple tokens like {{random.name}} to your JSON, you get fresh, realistic data every time your bin is accessed. It's like having a mini data generation engine built right into your mock API.

Perfect For

  • Frontend development with realistic, varying data
  • Testing how your UI handles different data lengths and formats
  • Demos and presentations with fresh data each time
  • API prototyping with realistic response patterns

Real World Uses

  • User profile pages with varying user data
  • Financial applications with random transaction amounts
  • E-commerce product listings with varying prices and IDs
  • Chat applications with random message content

Available Tokens

Tokens are special placeholders that get replaced with random data when your bin is accessed. They're designed to be intuitive and easy to remember - just wrap them in double curly braces like this: {{random.type}}

Basic Tokens

  • {{random.name}}Generates a full name
  • {{random.email}}Generates an email address
  • {{random.uuid}}Generates a UUID

Numbers & Dates

  • {{random.number(min,max)}}Number in range
  • {{random.date}}Recent date
  • {{random.boolean}}True or false

Examples

Let's look at some common scenarios where tokens can make your life easier. Each example shows both the input JSON (what you save in your bin) and an example output (what you get when accessing the bin).

Basic Usage

Input JSON:

{
  "name": "{{random.name}}",
  "email": "{{random.email}}"
}

Example Output:

{
  "name": "John Smith",
  "email": "john.smith@example.com"
}

Numbers with Parameters

Input JSON:

{
  "age": "{{random.number(18,65)}}",
  "score": "{{random.number(0,100)}}"
}

Example Output:

{
  "age": 32,
  "score": 87
}

Complex Object

Input JSON:

{
  "user": {
    "id": "{{random.uuid}}",
    "name": "{{random.name}}",
    "bio": "{{random.paragraph}}",
    "preferences": {
      "theme": "{{random.color}}",
      "notifications": "{{random.boolean}}"
    }
  }
}

Example Output:

{
  "user": {
    "id": "123e4567-e89b-12d3-a456-426614174000",
    "name": "Alice Johnson",
    "bio": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.",
    "preferences": {
      "theme": "#FF5733",
      "notifications": true
    }
  }
}

Pro Tips

While tokens are powerful, here are some tips to get the most out of them:

  • Consistency in Testing:

    When you need the same random value multiple times in your response, save the bin's response and use that fixed data for your tests.

  • Combine with Conditions:

    Use tokens together with SuperBins conditions to create dynamic, realistic error scenarios or edge cases.

  • Token Placement:

    Tokens work anywhere in your JSON strings - at the start, middle, or end. This lets you create patterns like "User-{{random.uuid}}" or "{{random.name}}'s Profile".

  • Keep it Real:

    While it's tempting to use random data everywhere, focus on varying the data that actually needs to be dynamic for your testing or development needs.