---
chapter: 10
title: Variables
throughline: real-estate property listings
requires_chapter: 08-automatic-subtitles
source: api/endpoints/00_common/j2v-lib-evaluator.js
last_reviewed: 2026-07-14
---

# 10. Variables

The address "123 Oak Street" and the price "$849,000" are hard-coded in five different places across our movie. Every new listing means find-and-replace. This chapter moves those values into a `variables` object and references them with `{{name}}` placeholders. One JSON, dozens of properties.

**Prerequisites:** [chapter 8](@/tutorials/08-automatic-subtitles). Variables work the same way for any string property.

## Step 1 — Declare variables at movie level

The `variables` object lives at the top level. Keys should use only letters, numbers, and underscores — any other character is silently replaced with an underscore. Names starting with `?`, `$`, or `@` are reserved: those variables are silently dropped. Neither case is a validation error — the render proceeds and the affected placeholders come out renamed or unresolved.

```json
{
  "variables": {
    "address": "123 Oak Street",
    "price": "$849,000",
    "bedrooms": "4",
    "agent_name": "Jordan Lee"
  }
}
```

## Step 2 — Reference variables in strings

Any string field in the movie may include `{{name}}` placeholders that resolve at render time. Update the title card and the voice script:

```json
{
  "type": "component",
  "component": "basic/000",
  "settings": {
    "headline": "FOR SALE",
    "subline": "{{address}}"
  }
}
```

```json
{
  "type": "voice",
  "text": "Welcome to {{address}} — a {{bedrooms}}-bedroom home, listed at {{price}}.",
  "voice": "en-US-EmmaMultilingualNeural",
  "start": 1.5
}
```

```json
{
  "type": "html",
  "tailwind": true,
  "wait": 0.5,
  "html": "<div class='inline-flex items-center gap-2 px-6 py-4 rounded-xl bg-emerald-700 text-white text-5xl font-bold shadow-lg'>💰 {{price}}</div>",
  "position": "bottom-right",
  "x": -60,
  "y": -60,
  "start": 4,
  "duration": 12
}
```

## Step 3 — Scene-level variables

Variables can also live on a scene. Scene variables override movie variables for that scene only. This is useful when the same template needs different captions per scene.

```json
{
  "duration": 4,
  "transition": { "style": "fade", "duration": 0.5 },
  "variables": { "room_name": "Master Bedroom" },
  "elements": [
    { "type": "image", "src": "https://cdn.json2video.com/assets/images/sample-house-bedroom.jpg" },
    { "type": "text", "text": "{{room_name}}", "position": "top-left", "x": 60, "y": 60 }
  ]
}
```

Resolution order: scene → movie. If the same name is defined in both, the scene wins inside that scene.

## Step 4 — Plug in a different property

Change the property by editing one section, not the whole movie:

```json
{
  "variables": {
    "address": "47 Cedar Avenue, Seattle, WA",
    "price": "$1,200,000",
    "bedrooms": "5",
    "agent_name": "Pat Morgan"
  }
}
```

Re-submit the same movie — the title card, voice-over, subtitles, and price tag all update.

## The complete final JSON

```json
{
  "resolution": "full-hd",
  "variables": {
    "address": "123 Oak Street",
    "price": "$849,000",
    "bedrooms": "4",
    "agent_name": "Jordan Lee"
  },
  "elements": [
    {
      "type": "audio",
      "src": "https://cdn.json2video.com/assets/audios/uplifting-corporate.mp3",
      "volume": 0.4
    },
    {
      "type": "voice",
      "text": "Welcome to {{address}} — a {{bedrooms}}-bedroom home, listed at {{price}}.",
      "voice": "en-US-EmmaMultilingualNeural",
      "start": 1.5
    },
    {
      "type": "subtitles",
      "language": "en",
      "settings": {
        "style": "boxed-word",
        "font-family": "Inter",
        "font-size": 90,
        "word-color": "#FFFFFF",
        "line-color": "#FFFFFF",
        "outline-color": "#000000",
        "position": "bottom-center",
        "all-caps": true,
        "box-color": "#0E7C66"
      }
    },
    {
      "type": "html",
      "tailwind": true,
      "wait": 0.5,
      "html": "<div class='inline-flex items-center gap-2 px-6 py-4 rounded-xl bg-emerald-700 text-white text-5xl font-bold shadow-lg'>💰 {{price}}</div>",
      "position": "bottom-right",
      "x": -60,
      "y": -60,
      "start": 4,
      "duration": 12
    }
  ],
  "scenes": [
    {
      "duration": 4,
      "elements": [
        {
          "type": "component",
          "component": "basic/000",
          "settings": { "headline": "FOR SALE", "subline": "{{address}}" }
        }
      ]
    },
    {
      "duration": 4,
      "transition": { "style": "fade", "duration": 0.5 },
      "variables": { "room_name": "Exterior" },
      "elements": [
        { "type": "image", "src": "https://cdn.json2video.com/assets/images/sample-house-front.jpg" },
        { "type": "text", "text": "{{room_name}}", "position": "top-left", "x": 60, "y": 60 }
      ]
    },
    {
      "duration": 4,
      "transition": { "style": "fade", "duration": 0.5 },
      "variables": { "room_name": "Chef's Kitchen" },
      "elements": [
        { "type": "image", "src": "https://cdn.json2video.com/assets/images/sample-house-kitchen.jpg" },
        { "type": "text", "text": "{{room_name}}", "position": "top-left", "x": 60, "y": 60 }
      ]
    },
    {
      "duration": 4,
      "transition": { "style": "fade", "duration": 0.5 },
      "variables": { "room_name": "Master Bedroom" },
      "elements": [
        { "type": "image", "src": "https://cdn.json2video.com/assets/images/sample-house-bedroom.jpg" },
        { "type": "text", "text": "{{room_name}}", "position": "top-left", "x": 60, "y": 60 }
      ]
    }
  ]
}
```

## Expected output

The chapter-8 listing, but every appearance of the address or price now resolves from variables. Swap the variables block to generate a video for a completely different property — same JSON, different output.

## What you learned

- `variables` is a flat object of `key: value` pairs at movie or scene level.
- Reference a variable inside any string with `{{name}}`.
- Scene variables shadow movie variables inside that scene only.
- Variable names starting with `?`, `$`, or `@` are silently dropped; any other non-alphanumeric character is replaced with an underscore.

## Previous chapter / Next chapter

[← 8. Automatic subtitles](@/tutorials/08-automatic-subtitles) · [11. Templates →](@/tutorials/11-templates)
