Infinity in JSON – Handle Infinity and -Infinity Safely

Infinity and -Infinity exist in JavaScript but standard JSON only represents finite numbers. Repair requires an explicit semantic choice for downstream data.

Runs locally
Ready to repair

Paste malformed JSON or AI-generated structured output.

55 chars

Run the repair to preview the corrected document.

0 chars

Try a focused case

Common invalid JSON examples

Load one broken syntax pattern at a time, run the repair, and compare the declared rule with the resulting repair log.

Trailing commas

Trailing comma

Remove commas that appear immediately before closing object or array delimiters without touching commas stored inside string values.

{"roles":["admin","editor",],"active":true,}

Review: Confirm that each removed comma was only formatting punctuation and did not represent an intentionally missing value.

JavaScript-style object

Trailing comma · Single-quoted string · Unquoted object key

Convert identifier-like keys and single-quoted strings from a JavaScript object literal into standard JSON syntax.

{
  name: 'VetaTool',
  features: ['repair', 'diff',],
}

Review: Review every inferred key and string boundary because apostrophes and JavaScript escaping can make the intended text ambiguous.

JavaScript comments

JavaScript comment

Remove line and block comments that are legal in some configuration formats but are not allowed by the JSON grammar.

{
  // feature flag
  "enabled": true /* temporary rollout */
}

Review: Check whether a removed comment contained operational context that should be preserved outside the repaired JSON document.

Markdown code fence

Markdown code fence

Strip one outer Markdown fence commonly added around JSON returned by chat assistants, documentation, or copied code blocks.

```json
{"name":"Ada","active":true}
```

Review: Verify that the fence wrapped the entire payload and that no explanatory prose outside the code block was discarded.

Unsupported JavaScript literals

Undefined value · Non-finite number

Replace undefined and non-finite numbers that JavaScript accepts but standard JSON cannot represent with reviewable null placeholders.

{"missing":undefined,"score":NaN,"limit":Infinity}

Review: Decide whether null is the correct business value, or whether the property should be removed or represented another way.

Missing and redundant commas

Missing comma · Redundant comma

Insert a separator between adjacent complete values and remove extra separators only where surrounding tokens identify the boundary.

{"first":1 "second":2,,"third":3}

Review: Confirm that inferred separators match the intended property boundaries and that no omitted value was represented by an empty slot.

Mismatched delimiters

Mismatched delimiter

Replace or add a closing brace or bracket when the nested token stack identifies one bounded structural mismatch.

{"items":[1,2,3}

Review: Inspect the surrounding nesting because heavily damaged objects can have more than one plausible brace or bracket completion.

Escaped JSON string

Escaped JSON string

Decode one outer JSON string layer when a field contains an escaped object or array instead of a directly nested JSON value.

{"payload":"{\"name\":\"Ada\",\"active\":true}"}

Review: Confirm that the field is intended to become a nested object rather than remain a string consumed by another downstream system.

Repair log

Run the repair to see each change and why it was made.

No repair run yet.

JSON unsupported literal

Why Infinity is outside the JSON number grammar

JSON numbers are finite decimal values. JavaScript's positive and negative Infinity therefore cannot be transferred as JSON numbers without choosing another representation. This tool is free to use. No account or payment is required.

Last updated

What you can do here

  • Browser-local JSON processing
  • Route-specific malformed JSON example
  • Focused parser or repair guidance
  • Broken and corrected JSON example
  • Related JSON problem navigation

Steps

  1. Locate Infinity or -Infinity and identify whether it represents overflow, an open-ended limit, or missing data.
  2. Review the null placeholders produced by JSON Repair rather than accepting them blindly.
  3. Choose a representation that the consumer's schema and business logic explicitly understand.

Infinity often represents a domain concept, not a portable number

An unbounded maximum, failed calculation, or overflow condition may all produce Infinity in JavaScript, but those cases usually deserve different representations in an API contract.

  • Open-ended upper or lower limits.
  • Numeric overflow from a computation.
  • Handwritten JavaScript configuration copied into JSON.

Avoid magic finite replacements

Substituting Number.MAX_VALUE or another huge number changes the meaning and can create downstream bugs. Prefer an explicit nullable/status representation when the schema allows it.

Infinity JSON repair example

The repair candidate converts both non-finite literals to null placeholders for explicit review.

JSON with Infinity

{
  "upperLimit": Infinity,
  "lowerLimit": -Infinity
}

Reviewable valid JSON

{
  "upperLimit": null,
  "lowerLimit": null
}

Common questions

Frequently asked questions

Is Infinity valid JSON?

No. Standard JSON does not define Infinity or -Infinity literals.

Can I encode Infinity as a very large number?

Only if your domain explicitly defines that convention. A magic large number is not equivalent to mathematical infinity and can be misleading.

Why does JSON.stringify turn non-finite numbers into null?

JavaScript's JSON serialization behavior normalizes non-finite numeric values rather than emitting invalid JSON number tokens. Your data contract should still define what that null means.

Debugging a specific JSON issue? Browse JSON troubleshooting.