Skip to main content

SRT to JSON

Converts SRT (SubRip Text) subtitle files to JSON format, enabling programmatic manipulation of subtitle data. The node reads an SRT file and outputs a structured JSON array containing subtitle entries with timing and text information.

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

  • SRT File Path - Path to the SRT subtitle file to convert. Must be a valid file path pointing to an existing .srt file.

Output

  • jsonFormat - JSON array of subtitle objects. Each object contains:
    • start - Start time in milliseconds (number)
    • end - End time in milliseconds (number)
    • text - Subtitle text content (string)

How It Works

The SRT to JSON node converts subtitle files by:

  1. Reading the SRT file from the specified path
  2. Parsing each subtitle entry (number, timestamps, and text)
  3. Converting timestamps from SRT format (HH:MM:SS,mmm) to milliseconds
  4. Creating a JSON object for each subtitle with start, end, and text fields
  5. Returning a JSON array containing all subtitle objects

SRT Format Structure

Standard SRT files follow this 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

JSON Output Structure

The node outputs JSON in this format:

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

Practical Examples

Example 1: Extract Subtitles for Analysis

Convert a movie subtitle file to JSON for text analysis:

  • SRT File Path: C:\videos\movie_subtitles.srt
  • Output: JSON array stored in {{msg.jsonFormat}}

Use case: Extract all subtitle text for sentiment analysis, keyword detection, or content summarization.

Example 2: Subtitle Translation Workflow

Load subtitles as JSON, translate text, and regenerate SRT:

1. SRT to JSON: Load original subtitles
2. For each subtitle in {{msg.jsonFormat}}:
- Translate subtitle.text to target language
- Keep start and end times unchanged
3. JSON to SRT: Save translated subtitles

Use case: Automate video subtitle translation for multiple languages.

Example 3: Adjust Subtitle Timing

Convert to JSON to modify timing programmatically:

  • SRT File Path: /media/video_subtitles.srt
  • Process: Add 2000ms delay to all start/end times
  • Output: Modified JSON for regenerating synchronized subtitles

Use case: Synchronize subtitles after video editing or trimming.

Example 4: Search Subtitles by Timestamp

Load subtitles and find text at specific time:

1. SRT to JSON: Convert subtitle file
2. Filter where start <= 30000 and end >= 30000
3. Return matching subtitle text

Use case: Find what was said at a specific timestamp in a video.

Example 5: Batch Process Multiple Subtitle Files

Process all SRT files in a folder:

For each file in "C:\subtitles\*.srt":
- SRT to JSON: Convert file
- Store in database with filename and timestamp
- Generate searchable subtitle archive

Use case: Build a searchable database of video subtitles for content management.

Example 6: Extract Dialogue Duration Statistics

Analyze subtitle timing patterns:

1. SRT to JSON: Load subtitles
2. For each subtitle in jsonFormat:
- Calculate duration: end - start
- Track speaking time vs silence
3. Generate statistics report

Use case: Analyze video pacing and dialogue distribution.

Example 7: Merge Multiple Subtitle Files

Combine subtitles from different sources:

1. SRT to JSON: Convert subtitle file 1
2. Store in array1
3. SRT to JSON: Convert subtitle file 2
4. Merge arrays and sort by start time
5. JSON to SRT: Generate combined file

Use case: Combine subtitles from multiple languages or sources into one file.

Tips for Effective Use

  • Valid file paths: Always use absolute paths or verify relative paths are correct
  • File encoding: Ensure SRT files are UTF-8 encoded for proper text handling
  • Error handling: Use Try-Catch nodes to handle missing or corrupted files gracefully
  • Data validation: Check that the output JSON array is not empty before processing
  • Timing precision: All timestamps are in milliseconds for precise calculations
  • Multi-line text: SRT text can span multiple lines; the node preserves formatting
  • Performance: Processing large subtitle files (1000+ entries) is fast and efficient
  • Memory usage: Large subtitle files are loaded into memory; consider file size for batch operations
  • Automation chains: Combine with JSON manipulation nodes to modify subtitle data

Common Errors and Solutions

Error: "SRT File Path cannot be empty"

Solution: Provide a valid file path to the SRT subtitle file.

Error: File not found

Solution:

  • Verify the file path is correct and the file exists
  • Check file permissions and read access
  • Use absolute paths instead of relative paths
  • Ensure the file extension is .srt

Error: Cannot read SRT file

Solution:

  • Verify the file is a valid SRT format
  • Check file is not corrupted or locked by another process
  • Ensure file encoding is compatible (UTF-8 recommended)
  • Verify the file is not empty

Error: Invalid SRT format

Solution:

  • Check the SRT file follows standard format:
    • Sequential numbers
    • Timestamp format: HH:MM:SS,mmm --> HH:MM:SS,mmm
    • Text content
    • Blank line separators
  • Remove any invalid characters or formatting
  • Verify timestamps are properly formatted

Empty output array

Solution:

  • Verify the SRT file contains subtitle entries
  • Check if the file is actually an SRT file (not renamed from another format)
  • Inspect file content manually to verify format

Incorrect timestamp conversion

Solution:

  • Verify SRT timestamps use comma separator (00:00:01,000) not period
  • Check timestamps are in valid range (00:00:00,000 to 99:59:59,999)
  • Ensure no negative timestamps exist in the file

RPA Use Cases

  • Video content analysis: Extract subtitle text for indexing and search
  • Translation automation: Convert subtitles for translation workflows
  • Content moderation: Analyze subtitle text for compliance checking
  • Video editing: Adjust subtitle timing after video modifications
  • Media management: Index video content based on subtitle data
  • Accessibility: Process subtitles for closed caption generation
  • Quality assurance: Validate subtitle timing and content
  • Multi-language production: Automate subtitle translation pipelines
  • Video archiving: Extract and store subtitle metadata
  • Search functionality: Enable timestamp-based video search

Best Practices

  • Validate input: Always check the SRT file exists before processing
  • Error logging: Log file paths and errors for troubleshooting
  • Data storage: Store converted JSON in variables for further processing
  • Batch processing: Use loops to process multiple subtitle files efficiently
  • Backup originals: Keep original SRT files before making modifications
  • Test with samples: Validate conversion with small files before batch operations
  • Format validation: Verify SRT format before conversion to avoid parsing errors
  • Encoding standards: Use UTF-8 encoding for international character support
  • Performance monitoring: Track processing time for large subtitle files
  • Integration: Combine with other nodes for complete subtitle automation workflows