dcm2niix BIDS Output: JSON Sidecars, Filenames and fMRIPrep

dcm2niix BIDS Output: JSON Sidecars, Filenames and fMRIPrep

If you plan to run fMRIPrep or share data as a BIDS dataset, dcm2niix is not just converting your images, it is producing the metadata backbone of your whole project. The NIfTI files carry the brain data, but the JSON sidecars carry the story: what sequence ran, with what timing, in what direction. This guide explains how dcm2niix BIDS output works, how to shape filenames for BIDS, what still needs manual arranging, and how the pieces fit into an fMRIPrep run.

What BIDS expects from you

BIDS, the Brain Imaging Data Structure, is a community standard for organizing neuroimaging data. It says where files go, what they are called, and what metadata travels with them. A structural scan for subject one, for example, belongs in a folder like sub-01/anat with a name that says what it is. Analysis tools that understand BIDS, including fMRIPrep, can then find everything without a custom configuration for every dataset.

dcm2niix does a large part of this job automatically. Its BIDS sidecar option (-b y, on by default) writes a JSON file next to each NIfTI image, holding the DICOM metadata that BIDS requires: repetition time, echo time, slice timing, phase encoding direction, and more. Without those sidecars, much of fMRIPrep’s work, like distortion correction, would be guesswork.

Sidecars: what is inside and why it matters

Open a JSON sidecar and you will see a readable list of acquisition parameters. The ones you will check most often are:

  • RepetitionTime and EchoTime, the core timing of the sequence
  • SliceTiming, the order and timing of slice acquisition, which slice timing correction depends on
  • PhaseEncodingDirection, which distortion correction needs to know which way the image stretches
  • TaskName and other task details for functional runs, where present in the DICOM

These values come straight from the scanner’s DICOM headers, translated into BIDS terms. That translation is valuable because DICOM headers are vendor specific and hard to read by hand, while BIDS sidecars are consistent. When a sidecar value looks wrong, the cause is usually in the original DICOM or in the conversion settings, and it is worth investigating before you preprocess.

Anonymized sidecars with -ba

The -ba option controls whether BIDS sidecars are anonymized, and it defaults to y. That means identifying details are kept out of the sidecar by default, which is the behavior you want whenever data might be shared. It is not, however, a complete privacy solution. Raw DICOM still holds patient names, IDs, and dates in its headers, and that raw data must stay on secured systems. Think of -ba as one layer of a privacy workflow, not the whole workflow. Never post raw DICOM publicly, and anonymize properly before sharing anything.

Shaping filenames for BIDS

dcm2niix filenames come from the -f pattern, and the BIDS style pattern -f “%f_%p_%s” is a common starting point: input filename, protocol name, and series number combined. That gives you unique, informative names, but BIDS names follow their own stricter rules, with entities like sub, ses, task, and run in a fixed order.

In practice, most labs treat dcm2niix output as step one and renaming as step two. Convert with a clear pattern, then use a BIDS converter or a small script to place files into sub-01/anat, sub-01/func, and similar folders with proper BIDS names. Some tools automate this mapping from the sidecar metadata. Either way, check the result with the BIDS validator before you call the dataset done. The validator catches naming and metadata mistakes that are painful to fix later.

From BIDS dataset to fMRIPrep

fMRIPrep expects a valid BIDS dataset as input. It reads the NIfTI images and the JSON sidecars, works out what each scan is, and runs preprocessing: motion correction, distortion correction, alignment, and more. The quality of its output depends directly on the quality of your conversion. Missing sidecars mean missing parameters, and wrong phase encoding directions mean distortion correction that pushes the image the wrong way.

A good habit is to run fMRIPrep on one subject first and inspect its reports carefully. Check that fieldmaps were found and applied, that slice timing correction used the sidecar values, and that the outputs align sensibly with anatomy. If something is off for one subject, it is usually off for all of them, and the fix usually lives in the conversion step, not in fMRIPrep settings.

Diffusion data in BIDS

Diffusion scans follow the same pattern with two extra files: .bval and .bvec, which record diffusion weightings and gradient directions. dcm2niix writes these automatically for diffusion series, and BIDS expects them sitting next to the diffusion NIfTI and JSON. If your diffusion output lacks them, check that the series really was diffusion weighted and that the conversion completed normally. Tractography tools will not run without them.

Common BIDS conversion mistakes

  • Missing JSON sidecars. Check that -b is y. Without sidecars, your dataset is not really BIDS, and fMRIPrep will struggle.
  • Duplicate or vague filenames. A pattern without a series number or protocol component can collide across series. Include %s and %p in your pattern.
  • Files in the wrong folders. dcm2niix output is flat by default. Placing files into sub/ses/modality folders is still your job, or your BIDS converter’s job.
  • Unrenamed task names. Functional sidecars may carry a task name from the scanner that does not match your BIDS task label. Fix it during renaming, not after preprocessing.
  • Skipping validation. The BIDS validator exists to catch exactly these mistakes. Run it before you share or preprocess at scale.

Validating your BIDS dataset

Before you share a BIDS dataset or feed it to fMRIPrep at scale, run the BIDS validator on it. The validator checks folder structure, filenames, and required metadata, and it reports errors and warnings in plain language. Treat errors as blocking: fix them before you continue. Treat warnings as a review list: some are harmless for your study design, but each one deserves a conscious decision rather than a shrug. Validating early, on one or two subjects, is far cheaper than validating at the end, when a systematic naming mistake has spread across a hundred subjects and must be fixed everywhere.

When sidecar values disagree with the protocol

Sooner or later a sidecar will disagree with your protocol sheet. Perhaps the repetition time differs, or the phase encoding direction is not what the scanning plan promised. When that happens, trust the investigation, not either document alone. Check the original DICOM headers to see what the scanner actually recorded. Check with the scanning operator whether the protocol changed mid study. Check whether another subject shows the same value, which points to a systematic cause, or just one subject, which points to a one off error. Document what you find and how you resolved it. A dataset with a documented discrepancy is trustworthy; a dataset with a silently patched value is not.

Conclusion

dcm2niix BIDS output gives you the two things a modern pipeline needs: clean NIfTI images and rich JSON sidecars, with diffusion bval and bvec files where they belong. Anonymized sidecars are the default, and filename patterns like “%f_%p_%s” keep output organized. Your remaining job is placing and renaming files into proper BIDS folders and validating the result. Do that carefully, and fMRIPrep will have everything it needs to do its best work.

Read next:

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top