Codeharbor Format & Check
Format JSON, CSS and HTML and find syntax errors in JSON, YAML, JavaScript and TypeScript.
How it works
Paste code to re-indent JSON, CSS or HTML and to list syntax problems with line and column: JSON is parsed strictly, YAML with a documented subset parser, JavaScript and TypeScript with Codeharbor’s own tokenizer. Nothing is run.
- JSON: a strict RFC 8259 parser reports the first error with line and column (trailing commas, single quotes, comments and unclosed strings get their own messages) and warns about duplicate keys. Formatting keeps the key order and the exact spelling of numbers; short arrays of numbers stay on one line.
- YAML: a subset parser (block mappings and sequences, quoted and plain scalars, one-line flow collections, block scalars, comments, several documents) reports tabs in indentation, lines indented more or less than their siblings, missing colons, mixed lists and mappings, unclosed quotes and duplicate keys. Anchors and tags are accepted but not resolved.
- JavaScript/TypeScript: Codeharbor’s tokenizer finds unterminated strings, template literals, comments and regular expressions, unmatched or mismatched brackets, reserved words used as names and a few statement mistakes. TypeScript is first reduced to JavaScript by blanking its types (positions kept); enums, namespaces, decorators and parameter properties are reported as unsupported. This is not a full parser or a type checker.
- CSS formatting puts one declaration per line inside indented rule blocks; HTML formatting places block elements on their own lines and indents children while keeping inline content, <pre> and <textarea> as they are.
Sources
Part of Codeharbor
-
Codeharbor Coding IDE
A coding IDE in your browser: edit, preview and run web projects safely, then share them.
How to format JSON, CSS and HTML and find syntax errors in code
Pretty-print minified JSON, CSS and HTML and get syntax errors with line and column for JSON, YAML, JavaScript and TypeScript — without running the code.
What it is for
A single stray comma can break a configuration file or a build. This tool takes a piece of code, works out what language it is, and does two things:
- it re-indents JSON, CSS and HTML so that every value, declaration or element sits on its own line;
- it checks JSON, YAML, JavaScript, TypeScript, CSS and HTML and lists every problem with its line and column.
The code is only read as text, never executed. The Codeharbor app uses the same engine for its Problems panel and Format document, so the answers match.
It is not a full compiler: it does not know your types, imports or browser support, and Markdown is only checked, not reformatted.
Worked example
The first example is a minified package-style JSON object on one line:
{"name":"harbour-api","version":"1.4.0","port":8080,"features":{"tides":true,"weather":false},"allowedOrigins":["https://example.org"]}
With Language set to JSON and the default indentation of 2 spaces the tool answers:
Formatted JSON (lines: 1 → 12) with no errors.
Every key gets its own line, indented by two spaces; the nested features object and the allowedOrigins list open on their own lines.
The second example has two trailing commas:
"features": { "tides": true, },
}
The result is Checked JSON (lines: 5): 1 error. The Problems table names line 4, column 30 (the comma) — “A trailing comma is not allowed in JSON.” — and a warning explains that the file was not formatted because it is not valid. Remove that comma, run again, and the second one — after the closing brace, line 4, column 32 — is reported.
The YAML example has one key indented by three spaces instead of two. The tool reports line 5, column 4: This line is indented more than expected. In the TypeScript example a reduce( call is never closed; the error points at the closing brace on line 4: “Expected “)” to close the “(” on line 3, but found “}”.”
How to read the result
- Language — what was checked. With Detect automatically the file name (if given) wins; otherwise the content decides.
- Problems — errors stop a parser; warnings (for example a duplicate JSON key) mean the file works but probably not as you intend.
- Formatted code — only shown for JSON, CSS and HTML without errors. Copy it or download it.
Tips and common mistakes
- JSON is parsed strictly (RFC 8259): no comments, no trailing commas, no single quotes. JSON5 and JSONC are not accepted.
- YAML is checked with a documented subset parser: block mappings and lists, quoted and plain values, one-line
[ ]/{ }collections, block scalars and comments. Anchors and tags are accepted but not resolved. Tabs in indentation are always an error. - The JavaScript check finds unclosed brackets, strings, comments and template literals and a few statement mistakes; it does not replace a linter.
- HTML formatting keeps
<pre>and<textarea>exactly as they are and keeps short elements such as<li>Item</li>on one line.
FAQ
Is my code run or uploaded somewhere to check it?
It is sent to the tool like any other input and read as text only. Nothing is executed, stored or shared; the same check runs inside the Codeharbor app without leaving your browser.
Why is my JSON with comments reported as broken?
Standard JSON has no comments. Files such as tsconfig.json use “JSON with comments”, which this strict check does not accept. Remove the comments, or keep checking such files with the tool that reads them.
Can it format JavaScript or TypeScript?
No. JavaScript and TypeScript are checked for syntax problems, but only JSON, CSS and HTML are re-indented. For full formatting use your project’s formatter.
Does a file without errors mean my code works?
No. The check finds mistakes that stop a file from being read at all — unclosed brackets, bad commas, wrong indentation. Wrong values, missing imports and logic errors are not found.
Guide last updated:
For scripts and AI agents
- JSON API:
POST https://codeharborformat.usefulweb.site/api/v1/calculate(same calculation as this page) - Interface description: OpenAPI 3.1 · AI guide: llms.txt
- MCP server (Streamable HTTP):
https://codeharborformat.usefulweb.site/mcp· tool namecodeharbor_format
Example request
curl -s -X POST https://codeharborformat.usefulweb.site/api/v1/calculate \
-H 'content-type: application/json' \
-d '{"code":"{\"name\":\"harbour-api\",\"version\":\"1.4.0\",\"port\":8080,\"features\":{\"tides\":true,\"weather\":false},\"allowedOrigins\":[\"https://example.org\"]}","language":"json"}'