HTML To JSON Converter
HTML To XML, CSV, Text And Code
This HTML to JSON converter turns markup into a clean tree. It also writes XML, YAML, CSV, plain text, JavaScript strings and PHP strings. We upload nothing.
- FreePrice
- 9Outputs
- NoneSign-up
- NoneUploads
HTML to JSON Converter
Turn HTML into JSON, XML, YAML, CSV, text or code, and back
- Elements
- 0
- Attributes
- 0
- Size
- 0 B
Ready. Paste your code and pick the formats.
Run it on a test page before the live one
Keep a copy of your original code and try the result on a test page before you replace the live file. No automatic tool can see every way your site uses its code.
What An HTML To JSON Converter Does For You
HTML was created for Web Browsers, not for Data Processing. So, if you need the HTML data within a Script, Spreadsheet, or API Call, you will have to convert the format of the HTML. That is what this utility accomplishes.
First, type in the HTML code. After that, choose the output format you want. As you enter the HTML, the output is generated. When using JSON or YAML, the entire tree will be saved; when using XML, the HTML will be converted into clean markup; and when using CSV, the data from each row of a table will be extracted.
This tool converts HTML to plain text, a JavaScript string, and a PHP string. In addition, this tool can convert from a code string back to HTML. You just paste a code string into the tool and it will create the HTML for you.
At this point, you can use the output in any way you wish. For example, load the JSON file in a script; enter the CSV data in a spreadsheet; or insert the string into your programming language.
You keep all of the work on your end, in your web browser. So, your HTML/CSS code remains on your computer. This is important since many websites contain personal data (names, email addresses, etc.) and other sensitive info.
HTML To JSON, Tag By Tag
First, the tool reads your markup and builds a tree. Every tag becomes an object with a tag name. Attributes go in an attrs object, and nested tags and text go in a children list.
A link is now represented by an object that has an "a" tag, an "href" attribute and the link’s content as a child. This is true for all links on your page. The tree will retain the same ordering of your page as when you first created it.
As well as being forgiving, the reader will close any tags that would normally be closed by a browser (e.g. p, li and td). In addition, it decodes entities so that an ampersand entity is converted into a standard ampersand.
For further info, please refer to: HTML Living Standard
HTML To CSV From A Table
First, most pages will have a table containing your data. Once you have pasted the page and selected either CSV or TSV, the tool will read each row and cell of the table. In cases where there are multiple tables on the page, the user may select from a drop down menu of all tables present.

This tool will wrap a cell with commas or quotes within quotes. So, when you open the file in either Excel or Sheets, it will open without errors. Also, any header cells will become the first row of data.
After that, open the CSV in a spreadsheet or load it into a database.
HTML To Text
The text mode removes the tags and maintains the document’s format. A blank line follows all paragraphs and headings. List items are preceded by a dash, and each row of a table occupies its own line.
Scripts and style sheets are not displayed in the content. You can enable the display of links by checking the box, and each link will be followed by the URL within brackets.
HTML To JavaScript And PHP Strings
The tool escapes the HTML for you, so that if there are any quotes or line breaks in the HTML, they do not cause problems with the string.

You can use either single-quote (’), double-quote ("), a template literal (`), or a series of strings concatenated together for JavaScript. In contrast, with PHP, you may select from single-quote (’), double-quote ("), or a "nowdoc" block.
From A Code String Back To HTML
You can even run it backwards. You paste a JavaScript or PHP code snippet with a string in it, then select HTML as your output. The program will find all of the strings, join them together, and strip out any escape characters.
Also, it reads single quotes, double quotes, template literals and nowdoc blocks. It understands the usual escapes, such as a line break, a tab, a backslash and a Unicode code.
XML And YAML Output
The XML output complies with the requirements. Tags that lack content are closed by the tool, and attributes are both quoted and escaped. In cases where there are multiple top-level tags within the HTML being processed, the tool creates a single root tag to encompass them.
YAML is an alternative to the JSON tree that includes tag, attributes, and child elements. It has the advantage of being easier to view than the JSON format, and it can be copied and pasted directly into a configuration file.
Safe By Design
The tool views your HTML as text, never rendering it. So, a script within the HTML will not execute. By default, the tool leaves out both scripts and styles; but you may include the text of each should you need it. This is why the tool can be safely used on sites that you do not trust.
On this page
- The tool
- What An HTML To JSON Converter Does For You
- Using The HTML To JSON Converter, Step By Step
- What This HTML Converter Does Differently
- Habits For Moving Data Out Of HTML
- Common Conversion Mistakes This Tool Prevents
- Common Questions About The HTML To JSON Converter
- Handy Companions For Web Data
Keep going
See the HTML to JSON Converter at Work, Start to Finish
This brief video shows each step from start to finish. Choose your language below, and switch on captions if they help.
Using The HTML To JSON Converter, Step By Step
Four steps take you from markup to data.
Paste your HTML
Paste it, open a file, or load the sample.
Pick two formats
Select your starting format, then select the format you would like to have returned. You may switch between these formats with one simple click.
Set the options
Trim spaces, keep scripts, pick a table or choose a string style.
Copy or save
Copy the result, or save it with the right file type.
What This HTML Converter Does Differently
Many converters give you one output. This tool offers nine of them.
Nine outputs
JSON, YAML, XML, CSV, TSV, text, JavaScript, PHP and HTML.
Both directions
Turn code strings back into HTML in one step.
Forgiving reader
It handles missing end tags, loose attributes and entities.
Table to CSV
Pick any table in the page and get clean rows.
Scripts stay out
The tool never runs the markup, and it drops scripts by default.
Nothing leaves your tab
The work happens on your side, in your own browser. Your HTML never reaches us.
Habits For Moving Data Out Of HTML
A few simple habits keep the converted data clean.
- Paste just the section of the page you really need. A small block gives a small, clear result.
- Choose the format based on what it is for. Use JSON for scripts, CSV for tables and text for reading.
- Leave the trim option switched on. It removes blank text between tags and keeps the tree short.
- Check tables first. Make sure every table row has the same number of cells.
- Mind merged cells. Cells that span columns read as one cell, so check the result.
- Use nowdoc or template strings. They keep long HTML readable inside code.
- Never trust pasted code. Read the output as data only, and never paste it into a page unchecked.
- Keep entities in mind. The program will replace the entity with its corresponding character. For example, the ampersand entity would be replaced by an ampersand in the result.
- Run a small sample through first. Convert one block first. After that, convert the full page.
- Keep the original. The tool never changes your source, but a copy costs nothing.
- Mind private data. Remove names and emails before you share a result.
Common Conversion Mistakes This Tool Prevents
All of the above will ruin your data without warning. But the converter protects against all of the above.
Broken string quotes
The tool escapes quotes and line breaks before HTML goes into code.
Lost entities
The tool decodes entities once, so no double encoding creeps in.
Script content in data
Scripts and styles are left out unless you ask for them.
Commas inside cells
The tool wraps CSV cells with commas or quotes safely.
Missing end tags
Open paragraphs, list items and cells close the way a browser closes them.
Uploading private pages
Many converters send your HTML to a server. This one never does.
Common Questions About The HTML To JSON Converter
Does this HTML to JSON converter cost anything?
Yes. It doesn’t cost anything, doesn’t need an account and has no restrictions. The heavy work is done by your browser; so we don’t have to get our server bills reimbursed from you.
Is the HTML I paste kept on my device?
No. The browser parses the markup and produces the output. Your input is not transmitted to our server, nor do we store any part of it.
What does the JSON from this converter look like?
Each tag is an object with tag, attrs and children. Text sits in the children list as a string.
Can it convert HTML to CSV?
Yes, for tables. It reads each row and each cell. If there are several tables, you pick one.
What happens if my HTML has no table?
The CSV and TSV options will display a notice. You should use JSON, YAML or text for anything else you wish to upload.
How does the HTML to text option work?
The program takes out all tags, while keeping each paragraph, heading, list item, and row in a table on its own line.
Can it keep link addresses?
Yes. When you turn on the link option, the URL for each address will appear after that address’s link text in brackets.
Can I turn HTML into a JavaScript string?
Yes. Select JavaScript, then use single quotes, double quotes, a template literal or join the lines together.
Can I turn HTML into a PHP string?
Yes. Pick PHP and choose single quotes, double quotes or a nowdoc block.
Can it turn a code string back into HTML?
Yes. Enter your JavaScript or PHP snippet, select it for input, and choose HTML for output.
Does it run scripts in my HTML?
No. The tool only reads the markup as text. It renders and runs nothing.
Are scripts and styles in the output?
Not by default. Switch on Keep script and style content if you need them.
Will it repair broken HTML?
It parses the unorganized markup as if it were being read by a web browser. The parser will close all of your open paragraphs, list items, and table cells.
What happens to comments?
The tool drops HTML comments and the doctype, because they hold no data.
Does it decode entities?
Yes. An ampersand entity is converted into an ampersand, and the output format will need that it be escaped.
Can I open a file rather than paste?
Yes. Use Open a file. The tool picks the input type from the file name.
What is the biggest file the tool will accept?
A few megabytes. Very large pages may read slowly on a phone.
Can it read a whole web page?
Yes. Paste the page source. The tool reads the head and the body, and it skips scripts and styles by default.
Does it keep attribute order?
Yes. The order of attributes is kept in the same way they were written. When an attribute appears more than once, the first one will be used.
Why does my XML have a root tag?
XML needs one top tag. So the tool adds a root tag when your HTML has more than one.
Does it run on phones too, or only on desktops?
Yes. The panels stack and the boxes scroll. For long markup, a keyboard is still easier.
Handy Companions For Web Data
Converting is one step. These three tools handle the steps around it.
- JSON to HTML Table
Convert JSON into a tidy HTML table.
- Markdown to HTML Converter
Convert Markdown into HTML, or turn HTML back into Markdown.
- XML to JSON Converter
Turn XML into clean, typed JSON.
Ready To Convert Some HTML?
Paste your HTML code here, select two output formats, then download the results. No registration, no cost, all data remains local.