Getting started
fhir-resource-diff is a CLI and library for comparing and validating FHIR JSON resources — fast, local, no infrastructure dependencies.
Install
Section titled “Install”# Global install (recommended for CLI use)npm install -g fhir-resource-diff# orpnpm add -g fhir-resource-diff
# Project-local (for library use or CI)pnpm add -D fhir-resource-diffFirst commands
Section titled “First commands”Validate a resource
Section titled “Validate a resource”fhir-resource-diff validate patient.json# → validWith a specific FHIR version:
fhir-resource-diff validate patient.json --fhir-version R4valid ℹ For full FHIR schema validation, use the official HL7 FHIR Validator → https://confluence.hl7.org/display/FHIR/Using+the+FHIR+ValidatorThe note about the HL7 Validator is always shown when --fhir-version is specified — it’s a footer about scope, not a finding about your resource.
Compare two resources
Section titled “Compare two resources”fhir-resource-diff compare expected.json actual.jsonResourceType: PatientStatus: 3 difference(s) found
Changed: birthDate: "1974-12-25" → "1974-12-26" name[0].given[0]: "Peter" → "Pete"
Added: telecom[2].systemLook up a resource type
Section titled “Look up a resource type”fhir-resource-diff info PatientPatient (base)FHIR versions: R4, R4B, R5Documentation: R4: https://hl7.org/fhir/R4/patient.html R4B: https://hl7.org/fhir/R4B/patient.html R5: https://hl7.org/fhir/R5/patient.htmlQuick wins
Section titled “Quick wins”CI gate — fail a build step when resources diverge:
fhir-resource-diff compare expected.json actual.json --exit-on-diff --quietJSON output for automation:
fhir-resource-diff compare a.json b.json --format jsonIgnore noisy metadata fields:
fhir-resource-diff compare a.json b.json --preset metadataPipe from a FHIR server:
curl -s https://hapi.fhir.org/baseR4/Patient/592473 \ | fhir-resource-diff validate - --fhir-version R4Run from source (contributors)
Section titled “Run from source (contributors)”No build step needed during development:
git clone https://github.com/dnlbox/fhir-resource-diff.gitcd fhir-resource-diffpnpm install
pnpm cli -- compare examples/patient-a.json examples/patient-b.jsonpnpm cli -- validate examples/patient-a.jsonThe -- separator after pnpm cli is required so pnpm passes flags to the script rather than consuming them.
Next steps
Section titled “Next steps”- Validate command deep-dive — what it checks, what it skips, JSON output format
- Compare command deep-dive — diff output, –ignore, output formats
- CI/CD integration — GitHub Actions examples, exit codes, quiet mode
- CLI reference — all flags for all commands