---
slug: json-validator-calculator
title: "JSON Validator Calculator"
category: developer
updated: 2026-11-17
canonical: https://calcseed.com/c/developer/json-validator-calculator/
html: /c/developer/json-validator-calculator/
---

# JSON Validator Calculator

Validate JSON and see whether it is well formed, what root type it holds and how many keys it contains. Free and instant.

## Quick answer

**Quick answer:** with the default inputs ({
  "name": "Ada",
  "age": 36
}), the is valid is **2**. Change any input to update the result.

## Default calculation

Values computed by this calculator at exactly the default inputs listed below.

### Inputs (defaults)

| Input | Value | Unit |
| --- | --- | --- |
| JSON input | {
  "name": "Ada",
  "age": 36
} |  |

### Outputs at these defaults

| Output | Value | Unit |
| --- | --- | --- |
| Total keys | 2 |  |

## Formula

```text
total keys = keys in root + keys in every nested object
```

## Inputs

| Variable | Type | Unit | Default |
| --- | --- | --- | --- |
| JSON input | text |  | {
  "name": "Ada",
  "age": 36
} |

## Outputs

| Result | Format |
| --- | --- |
| Is valid | primary |
| Is valid | text |
| Root type | text |
| Total keys | number |
| Error | text |

## How it works

### What makes JSON valid

Valid JSON is a document that obeys the grammar of RFC 8259, and the grammar is stricter than JavaScript object literal syntax in four everyday ways: keys must be double-quoted strings, string values must use double quotes, no trailing comma may follow the last element, and comments do not exist. Numbers may not have leading zeros or a trailing + sign, and the literals true, false and null are the only bare words allowed.

A valid document parses into exactly one root value, and that root does not have to be an object. This validator accepts arrays, strings, numbers, booleans and even the bare word null as the entire document, then reports which of those the root is.

### What the validator reports

On success you get three facts: the root type, the total number of keys, and implicit confirmation that the parser consumed the document without error. On failure you get the parser error message with its exact position, which points at the offending character rather than the region around it.

The key count walks every nested object recursively. The default document {"name": "Ada", "age": 36} has 2 keys at the top level and 0 nested objects, so the count is 2. A document with an address object holding 4 keys inside a person object holding 2 would report 6, because the count is the sum over all objects, not just the root.

### Worked example at the default input

The default document is a 3-line object with 2 keys. Parsing succeeds, the root type is object, and the total key count is 2. Change one character and the outcome flips: a trailing comma after the age line produces a parse error, as does swapping the double quotes around name for single quotes. The document is only 3 lines long, yet two of the most common real-world mistakes are each one keystroke away from invalid.

### The errors that catch most documents

| Error | Example | Parser message style |
| --- | --- | --- |
| Trailing comma | {"a": 1,} | Expected double-quoted property name at position 8 |
| Single quotes | {&rsquo;a&rsquo;: 1} | Unexpected token &rsquo; in JSON at position 1 |
| Unquoted key | {a: 1} | Unexpected token a in JSON at position 1 |
| Comment | {/* x */} | Unexpected token / in JSON at position 1 |
| Trailing garbage | {} {} | Unexpected non-whitespace character after JSON at position 3 |

#### Reading the error position

The position in each message counts from the start of the whole document, so on a large file the fastest fix is to jump to that character offset rather than scanning line by line. Editors with a go-to-column feature make short work of it.

### JSON versus JavaScript literals

Because JSON grew out of JavaScript, the differences surprise people in one direction only: everything valid in JSON is valid in JavaScript, but plenty of valid JavaScript is invalid JSON. Unquoted keys, single quotes, template literals, comments, undefined and trailing commas all parse as JavaScript and all fail as JSON. Config files edited by hand are where the two worlds collide most often, since developers write what the runtime would accept and the JSON parser rejects.

#### The invisible characters

Two invisible characters cause failures that look impossible. A byte order mark copied from a Windows editor sits before the first brace and triggers Unexpected token at position 0. A non-breaking space pasted from a chat window between tokens does the same, and neither is visible in most editors. If a document looks perfect but fails at position 0 or at an odd offset, retype the surrounding characters.

### Where validation fits in a workflow

- Before committing a config file, validate it — a broken config fails at deploy time, not edit time
- After editing API payloads by hand, confirm the structure still parses before sending the request
- When a third party sends you a file that will not import, run it here first to separate syntax problems from data problems
- After minification, re-validate as a cheap insurance step — the JSON Minifier already refuses invalid input, but the check costs nothing

Validation only proves syntax, not meaning. A document can parse cleanly and still contain a string where your code expects a number, or a missing key. The root type and key count exist precisely to catch those shape-level surprises: if your API expects an object with 5 keys and the validator reports an array with 0 keys, no syntax fix will help — the document itself is the wrong shape.

## FAQ

### Can JSON have comments?

No. RFC 8259 defines no comment syntax, so a comment makes the document invalid. Files ending in .jsonc allow them, but standard JSON parsers reject any comment at any position.

### Are trailing commas allowed in JSON?

No. A comma after the last element of an object or array is invalid. In {"a": 1,} the parser fails at position 8, at the closing brace, because it expected another double-quoted key after the comma.

### Why are single-quoted strings rejected?

The JSON grammar defines strings with double quotes only. {&rsquo;a&rsquo;: 1} is valid JavaScript but invalid JSON — every quote around a key or string value must be the straight double-quote character.

### What does the total key count mean for nested objects?

It sums keys across every object in the document, recursively. The 2-key default example reports 2; a root object with 2 keys containing one nested object with 3 keys would report 5.

### Can the root of a JSON document be an array?

Yes. Arrays, strings, numbers, booleans and null are all valid roots. The validator reports the root type so you can compare it against what your consuming code expects.

### What is the difference between valid JSON and valid JavaScript?

JSON is a subset. Unquoted keys, single quotes, comments and trailing commas all work in JavaScript but fail in JSON. If it parses as JavaScript object literal syntax, it may still be invalid JSON.

### Why does my file fail at position 0 with nothing wrong visible?

The usual cause is an invisible byte order mark or a non-breaking space before the first character. Both are invisible in most editors. Retype the first brace or strip the BOM and the document will parse.

### Is a document that passes validation guaranteed to work in my API?

No. Validation proves syntax only. A payload can be valid JSON and still miss required keys or hold the wrong types, which is why the reported root type and key count are worth checking against the expected shape.

### How do I fix an error reported at a specific position?

The position counts characters from the start of the document. Jump to that offset in your editor, then look one or two characters back — the parser reports where it got confused, which is usually just after the actual mistake.

## Method and sources

Methodology: Conversions and formats follow the relevant IETF RFCs and IEEE standards, including RFC 4648 for Base64 and RFC 791 for IPv4 addressing.

Last updated: 2026-11-17.
- RFC 8259: The JavaScript Object Notation (JSON) Data Interchange Format.
