When a variable in your code might or might not contain JSON, you need a way to find out before you commit to JSON.parse.
Loading JSON Validator…
Confirm a string is valid JSON before parsing
Identifies exactly what makes the string invalid
Shows line and column of every error
Free, instant, runs in your browser
Drop the JSON Validator into any page — blog post, product docs, intranet, school portal — with a single line of HTML. Your visitors get the full tool, processed entirely in their browser. No backend, no uploads, no signup.
Embed code
<iframe
src="https://www.fixtools.io/json/json-validator?embed=1"
width="100%"
height="780"
frameborder="0"
style="border:0;border-radius:16px;max-width:900px;"
title="JSON Validator by FixTools"
loading="lazy"
allow="clipboard-write"
></iframe>Attribution-friendly: a small "Powered by FixTools" link appears in the embed footer.
A JSON string, in the RFC 8259 sense, is any sequence of bytes that conforms to the JSON grammar. The grammar is broader than developers usually expect. The top-level value can be an object, an array, a string, a number, a boolean, or null. So the value 42 by itself is valid JSON, as is true, as is the literal "hello" with the double quotes included. This matters when you write a quick check for whether a variable contains JSON: a naive starts-with-curly-brace test rejects valid JSON values that begin with a digit, a letter, or a double-quote character. If your data source ever returns top-level scalars, your check has to accommodate them.
The practical pattern for checking a string before parsing is to attempt the parse inside try-catch and decide policy in the catch clause. The block looks like try { const parsed = JSON.parse(candidate); handle(parsed); } catch { handleNonJSON(candidate); }. The interesting design choice is what handleNonJSON does. If the data is supposed to be JSON, the catch branch should log, alert, or return a typed error. If the field is a hybrid that legitimately holds either JSON or plain text, the catch branch is normal control flow. A standalone isValidJSON helper that returns a boolean is appropriate when you need to branch on the result without immediately parsing.
Edge cases that catch out developers writing string validators include the following. An empty string is not valid JSON. A whitespace-only string is not valid JSON. The value undefined is not a string at all and JSON.parse will coerce it to the literal text undefined, which then fails. Numbers with leading zeros, such as 007, are invalid per the grammar because they look like octal. Very long strings can blow the maximum call depth in some parsers if they contain deep nesting. Files saved with a UTF-8 BOM contain an invisible U+FEFF byte at the start that breaks the grammar even though the file looks empty up to that point. FixTools surfaces every one of these cases by name.
The distinction between a string validator and a string parser matters for performance-sensitive code paths. A pure validator answers the yes-or-no question of whether the input conforms to the grammar without producing the parsed value. A parser produces the in-memory data structure as a side effect of validation. JSON.parse in standard JavaScript is a parser: even when you only need the verdict, it still allocates the structure and then discards it if you ignore the return value. For batch validation of millions of strings, this allocation overhead adds up. Specialised libraries like simdjson and yyjson offer validate-only entry points that skip the allocation step and run measurably faster on bulk workloads. For typical interactive use, the standard parser is fast enough that the distinction is invisible, and the convenience of getting the parsed value for free outweighs any allocation cost.
Paste the string you want to check. FixTools confirms whether it is valid JSON and explains any issues, useful before writing JSON.parse in your code.
Step-by-step guide to validate a json string:
Copy the string value
Capture the exact string you want to check from wherever it lives: a variable inspector, a log line, an HTTP response body, a database row, or a localStorage entry. Copy the raw bytes rather than a rendered view so invisible characters and whitespace are preserved exactly as your code receives them.
Paste into FixTools
Paste the captured value into the FixTools JSON validator input. If you copied from a log that quoted the value, strip the surrounding quotes so the validator sees the same characters your runtime would see. Confirm the visible length matches the length you logged in code to rule out clipboard truncation.
Check the result
A green confirmation means the string conforms to RFC 8259 and JSON.parse will return cleanly. A red result includes the line and column of the failure and a description of what the parser expected at that point. Use the description to identify whether the cause is a syntax error, a wrong content type, or invisible characters.
Use in code
Once the sample validates, write the JSON.parse call with confidence. Keep a try-catch wrapper around it for production safety, because the next record may have a different shape than the sample you tested. The validator confirms the format for one specific input, not the entire universe of inputs your code will eventually see.
Common situations where this approach makes a real difference:
Full-stack developer
A developer stores user preferences as a JSON string in a SQL text column. On read, the loader calls JSON.parse directly and crashes intermittently in production. Investigation reveals that early rows were inserted with plain text descriptions before the team standardised on JSON. They paste failing rows into FixTools to confirm the shape, then add a validation step before parsing that falls back to a default preferences object when the column does not validate. The crash rate drops to zero and the legacy rows are migrated on read.
Data analyst
An analyst receives a CSV export where one column is supposed to contain JSON metadata. Inspection shows the column is inconsistent: some rows have complete JSON objects, some have truncated structures, and some have plain English descriptions. The analyst pastes representative samples from each shape into FixTools to understand the failure modes before writing a cleanup script. The validator confirms which rows are fixable JSON, which are truncated, and which were never JSON to begin with, which determines the right path for each group.
Backend developer
A backend developer writes a webhook handler that receives several event types. Some bodies are JSON, others are URL-encoded form data, and a few are XML for a legacy partner. They paste samples of each body into FixTools while writing the handler, which clarifies which content types are valid JSON and which need a different parser. The handler ends up branching on Content-Type with explicit parser selection rather than calling JSON.parse blindly and catching errors.
Mobile developer
A mobile developer reads a value from Android SharedPreferences during a version upgrade. The value might be a JSON-serialised object from the new format or a plain string from the previous version. They paste samples from both shapes into FixTools, confirm which one validates and which one does not, and design a migration that detects the format on read and rewrites the storage in the new shape. The decision tree is informed by ground truth rather than guessed.
Get better results with these expert suggestions:
Check the type before validating
Before calling JSON.parse, confirm that the value is actually a string with typeof value === "string". JSON.parse on undefined throws the cryptic Unexpected token u in JSON at position 0 because parse coerces the argument to the literal text undefined first. A type guard up front produces a clearer error and prevents you from accidentally parsing null, numbers, or objects that happened to slip through your type system.
Distinguish empty string from empty JSON
The empty string is not valid JSON. The smallest valid JSON object is the two-character text consisting of an open and a close brace, and the smallest valid array is similarly two characters. If you want a default value that represents emptiness, choose null or one of the empty container literals rather than the empty string. Storing the empty string as a default leaves you with a value that fails parse and forces every reader to special-case it.
Validate a sample before writing a parser
Before writing parsing code for a new data source, paste several representative strings into FixTools. This confirms the format, exposes any edge cases such as null values, missing fields, or inconsistent types, and lets you design parsing logic that handles the real shapes rather than the shapes you assumed. Discovering format quirks in a validator is much cheaper than discovering them in production after a deploy.
Log string length and first and last characters
When debugging a JSON string that fails validation, log the length of the string and the first and last fifty characters separately. This pinpoints truncation, which shows up as a string that is shorter than expected and ends mid-value, and wrong content type, which shows up as a string that starts with an HTML tag. You get diagnostic value without paying the cost of logging an entire potentially huge payload.
More use-case guides for the same tool:
Other tools you might find useful:
Open the full JSON Validator — free, no account needed, works on any device.
Open JSON Validator →Free · No account needed · Works on any device