HTML to JSON Converter

Convert an HTML document to JSON: the rows of its tables, its JSON-LD, or every element. Data types are detected for you, and the output is indented for easy reading.
Input
Output

Settings

How the input is converted. Each is explained below.

Tags

History

HTML is the language of the internet. It is what creates HTML pages (even this one). In the old days, HTML used to be static with some JavaScript added into the mix for dynamic behavior and effects. Then HTML was served dynamically from the server side with the advent of server side programming languages such as PERL, PHP, ASP. And now there is a new trend where HTML is again being served as static resources with JSON (from REST web services) and JavaScript making it dynamic.

JavaScript Object Notation (JSON), pronounced as Jason, is the most common data interchange format on the web. Douglas Crockford first released the JSON specification in the early 2000s. It is a simple format that is easier to comprehend than XML. It is also smaller in size because it does not have closing tags. A wide variety of programming languages can parse JSON files. They also support the serialization of data structures to JSON. You can copy JSON text to JavaScript and start using them without any modifications.

Settings explained

Mode
What is converted. The examples below are for this input:
<table style="width: 100%">
    <tr><th>Firstname</th><th>Lastname</th><th>Age</th></tr>
    <tr><td>Jill</td><td>Smith</td><td>50</td></tr>
    <tr><td>Eve</td><td>Jackson</td><td>94</td></tr>
</table>
Generic: every element becomes a JSON object or property
{
  "table": {
    "@style": "width: 100%",
    "tr": [
      { "th": ["Firstname", "Lastname", "Age"] },
      { "td": ["Jill", "Smith", "50"] },
      { "td": ["Eve", "Jackson", "94"] }
    ]
  }
}
Table: each row of a table becomes an object, named by the header row
[
  { "Firstname": "Jill", "Lastname": "Smith", "Age": 50 },
  { "Firstname": "Eve", "Lastname": "Jackson", "Age": 94 }
]
JSON-LD: every JSON-LD block in the page, as an array
[
  { "@context": "http://schema.org/", "@type": "Person", "name": "Jane Doe", "jobTitle": "Professor" },
  { "@context": "http://schema.org/", "@type": "Person", "name": "John Doe", "jobTitle": "Dancer" }
]
Auto picks the mode from what the document holds.
Value new line conversion
How line breaks inside a value are written: kept as they are, or replaced by a space, a comma, a comma and a space, a semi-colon, or a semi-colon and a space.
Comma and space
Line 1, Line 2, Line 3
Attribute prefix
In Auto and Generic modes, what goes in front of a property made from an HTML attribute - "@style" with the default. Leave it empty for no prefix.
Text property name
In Auto and Generic modes, the name of the property that holds an element's own text, when it has child elements too.
<p>Pre Header <h1>Title</h1> Post Header</p>

{
  "p": {
    "h1": "Title",
    "#text": ["Pre Header", "Post Header"]
  }
}
Indent
Whether the output is indented. Indented JSON is easier to read; without indentation it is compact, which is better for sending over a network.
Unescape JSON
If the input looks like HTML inside a JSON string, it is unescaped before converting.
Trim inside words
Several spaces in a row inside a value become one.
Convert all tables
On, every table in the document is converted and the output is an array with one array per table. Off, only the first table is.