Normalize
The normalize command transforms a FHIR resource into a canonical form — trimming whitespace, sorting object keys, and normalizing date representations — so that two semantically equivalent resources produce identical JSON output. This is most useful before comparing resources that were serialized by different systems.
Basic usage
fhir-resource-diff normalize patient.jsonThe normalized JSON is written to stdout by default.
What normalization does
The canonical preset (the default) applies:
- Trim strings — leading and trailing whitespace removed from all string values
- Sort object keys — keys within each JSON object sorted alphabetically, making key order stable across serializers
- Normalize dates — date/time strings brought into a consistent representation where possible
These transformations are non-destructive: the information content of the resource is preserved. The goal is eliminating serialization noise before a diff, not altering clinical data.
Named presets
# canonical (default) — full normalization
fhir-resource-diff normalize patient.json --preset canonical
# none — no transformations (round-trip through parser only)
fhir-resource-diff normalize patient.json --preset noneWriting to a file
fhir-resource-diff normalize patient.json --output normalized-patient.jsonWithout --output, the result is written to stdout.
FHIR version
fhir-resource-diff normalize patient.json --fhir-version R5The FHIR version is used for version-aware normalization where applicable. Without --fhir-version, the tool auto-detects from meta.fhirVersion or defaults to R4.
Using normalization before a diff
The typical workflow when comparing resources from different systems:
fhir-resource-diff normalize system-a-output.json --output a-normalized.json
fhir-resource-diff normalize system-b-output.json --output b-normalized.json
fhir-resource-diff compare a-normalized.json b-normalized.jsonOr directly in the compare step using --normalize:
fhir-resource-diff compare a.json b.json --normalize canonicalStdin
cat patient.json | fhir-resource-diff normalize - --output normalized.json
# Or pipe the output
fhir-resource-diff normalize patient.json | jq '.name'See also
- Compare command — using --normalize in compare
- CLI reference — all flags for
normalize