Skip to main content

JSON to SRT

Converts JSON subtitle data to SRT (SubRip Text) file format, enabling the creation of subtitle files from programmatically generated or modified data. The node takes a JSON array of subtitle objects and generates a properly formatted SRT subtitle file.

Common Properties

  • Name - The custom name of the node.
  • Color - The custom color of the node.
  • Delay Before (sec) - Waits in seconds before executing the node.
  • Delay After (sec) - Waits in seconds after executing node.
  • Continue On Error - Automation will continue regardless of any error. The default value is false.
info

If the ContinueOnError property is true, no error is caught when the project is executed, even if a Catch node is used.

Inputs

  • Subtitles Json - JSON array of subtitle objects. Each object must contain:
    • start - Start time in milliseconds (number)
    • end - End time in milliseconds (number)
    • text - Subtitle text content (string)
  • SRT Path to Save - Output file path where the generated SRT file will be saved. Must include the .srt file extension.

How It Works

The JSON to SRT node creates subtitle files by:

  1. Validating the input JSON array structure
  2. Processing each subtitle object in sequence
  3. Converting millisecond timestamps to SRT format (HH:MM:SS,mmm)
  4. Assigning sequential numbering to each subtitle entry
  5. Formatting subtitle text with proper line breaks
  6. Writing the complete SRT file to the specified path

JSON Input Structure

The input JSON must follow this format:

[
{
"start": 1000,
"end": 4000,
"text": "First subtitle text"
},
{
"start": 5000,
"end": 8000,
"text": "Second subtitle text"
}
]

SRT Output Format

The node generates SRT files in standard format:

1
00:00:01,000 --> 00:00:04,000
First subtitle text

2
00:00:05,000 --> 00:00:08,000
Second subtitle text

Practical Examples

Example 1: Generate Subtitles from Transcription

Create subtitle file from speech-to-text output:

  • Subtitles Json: {{msg.transcriptionData}}
  • SRT Path to Save: C:\videos\generated_subtitles.srt

Use case: Convert AI-generated transcriptions into subtitle files for videos.

Example 2: Create Translated Subtitles

Generate SRT file from translated subtitle data:

1. SRT to JSON: Load original English subtitles
2. For each subtitle:
- Translate text to Spanish
- Keep start/end timestamps
3. JSON to SRT: Save Spanish subtitle file

Use case: Automate multi-language subtitle creation for international content.

Example 3: Adjust Subtitle Timing

Modify timing and regenerate SRT file:

  • Input: Original subtitle JSON with timing issues
  • Process: Add 2000ms offset to all timestamps
  • SRT Path to Save: /media/synced_subtitles.srt

Use case: Fix subtitle synchronization after video editing.

Example 4: Generate Subtitles from Database

Create subtitle file from stored data:

1. Query database for video subtitle entries
2. Format results as JSON array with start, end, text
3. JSON to SRT: Generate subtitle file
4. Save to video output folder

Use case: Export subtitles from content management system to SRT format.

Example 5: Merge and Sort Subtitles

Combine multiple subtitle sources:

1. Load subtitle data from multiple sources
2. Merge into single JSON array
3. Sort by start timestamp
4. JSON to SRT: Generate unified subtitle file

Use case: Combine subtitles from different speakers or languages into one file.

Example 6: Split Subtitles by Duration

Create separate subtitle files for video segments:

For each time segment (0-300000ms, 300000-600000ms, etc.):
- Filter subtitles within time range
- JSON to SRT: Save segment-specific subtitle file
- Name files: part1.srt, part2.srt, etc.

Use case: Generate subtitle files for split video clips.

Example 7: Create Subtitles with Custom Formatting

Generate subtitles with specific styling:

[
{
"start": 1000,
"end": 4000,
"text": "<i>Narrator:</i> Welcome to the tutorial"
},
{
"start": 5000,
"end": 8000,
"text": "<b>Important:</b> Follow these steps"
}
]

Use case: Create styled subtitles with italic, bold, or other SRT-supported formatting.

Example 8: Batch Generate Subtitle Files

Process multiple JSON datasets:

For each video in videoList:
- Load subtitle JSON from video.subtitleData
- JSON to SRT: Save to video.outputPath + ".srt"
- Log success/failure status

Use case: Automate subtitle file generation for video processing pipeline.

Tips for Effective Use

  • JSON validation: Ensure JSON array structure is correct before processing
  • Required fields: All subtitle objects must have start, end, and text fields
  • Data types: start and end must be numbers (milliseconds), text must be string
  • Timestamp order: While not required, sorting subtitles by start time is recommended
  • File paths: Use absolute paths or ensure output directory exists
  • Overwrite behavior: The node will overwrite existing files at the output path
  • Multi-line text: Use \n in text field for multi-line subtitles
  • Special characters: UTF-8 encoding supports international characters
  • Timestamp range: Valid timestamps are 0 to 359999999 milliseconds (99:59:59,999)
  • Sequential numbering: The node automatically assigns sequential numbers starting from 1

Common Errors and Solutions

Error: "Subtitles Json cannot be empty"

Solution: Provide a valid JSON array with at least one subtitle object.

Error: "SRT Path to Save cannot be empty"

Solution: Specify a valid output file path including the .srt extension.

Error: "Invalid type for Subtitles Json"

Solution:

  • Ensure input is a JSON array, not an object or string
  • Verify the data structure matches the required format
  • Check that the JSON is properly formatted and parseable

Error: "Invalid subtitle type for Subtitles Json"

Solution:

  • Each array element must be an object with start, end, and text fields
  • Remove any null or invalid elements from the array
  • Verify all subtitle objects follow the correct structure

Error: "Invalid start type for Subtitles Json"

Solution:

  • Ensure start field is a number (not string)
  • Verify start values are in milliseconds
  • Check for null or undefined start values
  • Convert string timestamps to numbers before processing

Error: "Invalid end type for Subtitles Json"

Solution:

  • Ensure end field is a number (not string)
  • Verify end values are in milliseconds
  • Check for null or undefined end values
  • Ensure end timestamp is greater than or equal to start

Error: "Invalid text type for Subtitles Json"

Solution:

  • Ensure text field is a string (not number or object)
  • Check for null or undefined text values
  • Convert text to string type if needed
  • Verify text contains valid characters

Error: Cannot write file

Solution:

  • Verify the output directory exists
  • Check write permissions for the output path
  • Ensure disk space is available
  • Verify the path is not locked by another process
  • Use absolute paths instead of relative paths

Error: File path permission denied

Solution:

  • Run the automation with sufficient permissions
  • Check folder access rights
  • Verify the path is writable
  • Try a different output directory

Data Validation

Required JSON Structure

[
{
"start": <number>, // Required, milliseconds
"end": <number>, // Required, milliseconds
"text": "<string>" // Required, subtitle text
}
]

Valid Example

[
{
"start": 0,
"end": 3000,
"text": "Hello World"
},
{
"start": 3500,
"end": 7000,
"text": "This is a subtitle"
}
]

Invalid Examples

Missing required field:

[
{
"start": 1000,
"text": "Missing end field"
}
]

Wrong data type:

[
{
"start": "1000", // Should be number, not string
"end": 4000,
"text": "Invalid start type"
}
]

RPA Use Cases

  • Video production: Generate subtitle files from automated transcription services
  • Translation workflows: Create multi-language subtitle files programmatically
  • Content management: Export subtitles from databases to SRT format
  • Video processing pipelines: Automate subtitle generation in video creation workflows
  • Accessibility compliance: Generate closed caption files for media content
  • E-learning platforms: Create subtitles for educational video content
  • Social media automation: Generate subtitles for video posts
  • Live streaming archives: Convert chat logs or transcripts to subtitle format
  • Quality assurance: Generate test subtitle files with specific timing patterns
  • Media localization: Automate subtitle file creation for international markets

Best Practices

  • Validate input data: Check JSON structure before conversion
  • Sort by timestamp: Order subtitles by start time for proper playback
  • Handle errors gracefully: Use Try-Catch nodes for robust error handling
  • Verify output: Check generated SRT file is valid after creation
  • Backup data: Keep JSON source data for regeneration if needed
  • Test with players: Verify generated SRT files work with video players
  • Use consistent encoding: Ensure UTF-8 encoding for international characters
  • Timestamp validation: Verify end time is greater than start time
  • Gap detection: Check for timing gaps between consecutive subtitles
  • Overlap detection: Ensure subtitles don't overlap in time
  • File naming: Use descriptive names with language codes (e.g., movie_en.srt, movie_es.srt)
  • Directory organization: Store subtitle files in organized folder structures
  • Logging: Log successful conversions and any data issues encountered
  • Performance: Process large subtitle datasets in batches if needed
  • Version control: Keep track of subtitle file versions and modifications

Integration Examples

Example: Complete Translation Workflow

1. SRT to JSON: Load original subtitles (English)
2. For each subtitle in jsonFormat:
- Call translation API with subtitle.text
- Replace text with translated version
- Keep original start/end times
3. JSON to SRT: Save translated file (Spanish)
4. Repeat for each target language

Example: Subtitle Quality Check

1. SRT to JSON: Load subtitle file
2. Validate each subtitle:
- Check timing: end > start
- Check duration: end - start >= 1000ms
- Check text length: text.length <= 80 characters
- Check gaps: next.start - current.end >= 200ms
3. Fix issues in JSON data
4. JSON to SRT: Regenerate validated subtitle file

Example: Dynamic Subtitle Generation

1. Generate subtitle data from AI/ML model
2. Format as JSON array:
- Segment audio by silence detection
- Transcribe each segment
- Create subtitle object with timing and text
3. JSON to SRT: Save final subtitle file
4. Sync with video file