Skip to main content
SubtitleMatrix

TTML to JSON

Or paste subtitle text

What this conversion changes

1 thing is dropped or needs a decision

  • Format-specific content

    content the source format keeps outside its cues (non-cue blocks, header text, per-cue settings, commented-out events) — the target format has no place for it

This list comes from the capability matrix for these two formats, not from the particular file you loaded. A specific file may lose more if it uses features the format allows but the matrix does not model.

This page converts TTML to JSON. Drop a file in — or paste the text — and you get the JSON version back. The conversion runs entirely in your browser, so nothing is uploaded and no account is needed.

These two formats do not store the same things, and the difference is not cosmetic: format-specific content has nowhere to go in JSON. The list above comes from what the two formats can each express rather than from your file, so it is the same answer before you load anything.

One file is fine, and so is a whole season: the queue works through them in order and the results come down together as a single ZIP.

Examples

A typical TTML file, converted to JSON

Input

<?xml version="1.0" encoding="UTF-8"?>
<tt xmlns="http://www.w3.org/ns/ttml" xmlns:tts="http://www.w3.org/ns/ttml#styling" xml:lang="en">
  <head>
    <styling>
      <style xml:id="s1" tts:color="#FFFF00" tts:fontWeight="bold"/>
    </styling>
    <layout>
      <region xml:id="bottom" tts:origin="10% 80%" tts:extent="80% 20%"/>
    </layout>
  </head>
  <body>
    <div>
      <p begin="00:00:01.000" end="00:00:03.500" region="bottom" style="s1">Hello <span tts:fontStyle="italic">there</span>.</p>
      <p begin="00:00:03.500" end="00:00:06.000" region="bottom">How are you?<br/>Fine, thanks.</p>
    </div>
  </body>
</tt>

Output

{
  "version": 1,
  "cues": [
    {
      "start": 1000,
      "end": 3500,
      "lines": [
        {
          "text": "Hello there.",
          "tags": [
            {
              "kind": "italic",
              "start": 6,
              "end": 11
            }
          ]
        }
      ]
    },
    {
      "start": 3500,
      "end": 6000,
      "lines": [
        "How are you?",
        "Fine, thanks."
      ]
    }
  ]
}

Dropped in this output: format-specific content. Everything else matches line for line.

The same conversion on an awkward input

Input

<?xml version="1.0" encoding="UTF-8"?>
<tt xmlns="http://www.w3.org/ns/ttml" xmlns:tts="http://www.w3.org/ns/ttml#styling"
    xmlns:ttp="http://www.w3.org/ns/ttml#parameter"
    ttp:frameRate="25" xml:lang="en">
  <body>
    <div>
      <p begin="1.5s" dur="2s">Loaded from an offset and a duration.</p>
      <p begin="4s" end="00:00:06.50">A coarser clock spelling.</p>
      <p begin="00:00:07:00" end="00:00:08:12">Frames, at 25fps.</p>
      <p begin="9s"><span tts:color="#FF0000">Half-open</span> and Tom &amp; Jerry.</p>
    </div>
  </body>
</tt>

Output

{
  "version": 1,
  "cues": [
    {
      "start": 1500,
      "end": 3500,
      "lines": [
        "Loaded from an offset and a duration."
      ]
    },
    {
      "start": 4000,
      "end": 6500,
      "lines": [
        "A coarser clock spelling."
      ]
    },
    {
      "start": 7000,
      "end": 8480,
      "lines": [
        "Frames, at 25fps."
      ]
    },
    {
      "start": 9000,
      "end": 11000,
      "lines": [
        {
          "text": "Half-open and Tom &amp; Jerry.",
          "tags": [
            {
              "kind": "color",
              "start": 0,
              "end": 9,
              "value": "#FF0000"
            }
          ]
        }
      ]
    }
  ]
}

This is the kind of damage real files have — mixed line endings, stray whitespace, fields left empty. Compare it with the tidy example above to see what the parser forgives.

Frequently asked questions

What happens to the TTML prolog, its `<styling>` and `<layout>` tables in JSON?

Dropped, with one precise exception. A TTML file keeps its look and its layout in the head rather than in the words: the XML declaration and its namespace bindings, the `<styling>` table of named styles (`tts:color`, `tts:fontWeight`), the `<layout>` table of named regions (`tts:origin`, `tts:extent`), any `<metadata>`, and the `style` / `region` attributes a `<p>` uses to point at them. The JSON output does have a `styles` object and per-line `tags`, and styling written *inside* a paragraph (`<span tts:fontStyle="italic">`) is part of the line, so that does arrive — in the `tags` array. Nothing from the head is translated into the `styles` object, so that comes out empty.

What does the output look like when TTML becomes JSON?

Like JSON: an array of cue objects, each with its own `id`, `start` and `end`. Every TTML cue becomes one JSON cue, in the same order, with the same text.

Are the TTML timings exact in the JSON file?

Yes, to the millisecond — which is as fine as either format goes. TTML writes a moment as `00:00:04.126` and JSON writes the same moment as `4126`; nothing is rounded or shifted between the two, and a cue that was on screen for 2.9 seconds still is.

How does a two-line TTML cue come out in JSON?

As two entries in the cue's `lines` array. The pairing survives — the two TTML lines still belong to one subtitle in the JSON output, and a player shows them together.

Do TTML cues keep their order in the JSON output?

Yes, and they are sorted by start time on the way — earliest first, which is how every format here expects them and how players read them. If your TTML file listed its cues out of sequence, the JSON output puts them back in order; that is a change to the file's structure rather than its content, and it is deliberate.

Can I convert the JSON back to TTML?

Yes, and it has its own list: converting JSON to TTML drops karaoke. That list is different from the one above because the two formats keep different things.

Does the JSON output keep the TTML file's encoding?

No — the output is UTF-8, with Unix line endings and no byte-order mark, whatever the TTML file used. A file that arrives in UTF-16, or in a Windows single-byte encoding, is decoded on the way in (the result panel says so when that happens); what comes out is always the same UTF-8 JSON.

Related tools