← Developer guides
DEVELOPER GUIDE

Format JSON without losing numeric precision

Preserve number and escape tokens, export complete arrays, and understand which whitespace the JSON formatter changes.

Workspace 0.2.2 · Analyzer 0.1.0, formatter 0.1.0, checker 0.1.0 · Updated September 14, 2026

Preserve what the sender wrote

The FHIR Response Formatter accepts strict JSON, including objects, arrays and scalar values. It preserves number spelling, string and key escapes, member order and array order while changing formatting whitespace.

The FHIR R4 JSON guidance explains that native JavaScript number parsing can lose decimal precision and trailing zeros. Here, 2.00 remains 2.00, and a large integer does not pass through a JavaScript Number conversion.

Try the token-preservation example

Paste this synthetic JSON array. The resource-shaped objects demonstrate formatting only; the formatter does not check whether they are valid FHIR resources.

[
 {"resourceType":"Observation","valueQuantity":{"value":2.00},"large":9007199254740993,"label":"A\u0042"},
 {"resourceType":"Patient","id":"synthetic-only","note":"line\nnext"}
]

Expected properties of the formatted output:

Numeric tokens: 2.00; 9007199254740993
String tokens: "A\u0042"; "line\nnext"
Resource inventory: Observation, Patient
Exported top-level items: 2

The escaped label can decode to AB for inspection, while its exported token remains "A\u0042". The resource menu identifies objects with a string resourceType; it makes no validity claim.

Export the complete document

Selecting a resource changes the preview. Copy and Download still use the entire formatted document, including both array items above. Download requests a browser download; the site cannot confirm that you saved the file.

In module code, export result.formatted or result.compact directly. The inspection tree stores numbers as JSONNumber objects with a raw token. Do not reconstruct output with Number, JSON.stringify(result.value) or text read from the preview; numeric wrappers reject conversion and serialization.

Resolve ambiguous keys first

This input is rejected with the error code below. The two key tokens decode to the same name, so retaining only one would silently discard a value.

{"id":"first","\u0069d":"second"}
DUPLICATE_KEY

Understand the word lossless

  • Whitespace inside strings remains intact. Indentation, line breaks and other insignificant whitespace outside strings may change; this is not an original-byte archive.
  • Neither formatted nor compact output is a signature canonicalization format. Formatting also does not establish FHIR conformance.
  • Comments, trailing commas, duplicate keys and JavaScript expressions are rejected.
  • Limits are 1 MiB of UTF-8 input, 50,000 JSON values, 128 nested containers and 8,388,608 output characters. A resource menu can show at most 2,000 resources; complete output remains available.

All examples are synthetic. Use the linked tool to reproduce the result.

Browse all developer guides · Open JSON formatter