code: def add_metadata_to_bids_dataset(bids_path, metadata, json_file=None):
      """Add JSON file with specific metadata to BIDS dataset.
  
      Note no "BIDS validation" are performed on the metadata,
      or on the file path.
  
      Parameters
      ----------
      bids_path : :obj:`str` or :obj:`pathlib.Path`
          Path to the BIDS dataset where the file is to be added.
  
      metadata : :obj:`dict`
          Dictionary with metadata to be added to the JSON file.
  
      json_file :  :obj:`str` or :obj:`pathlib.Path`, default=None
          Path to the json file relative to the root of the BIDS dataset.
          If no json_file is specified, a default path is used
          that is meant to work well with the defaults of
          `create_fake_bids_dataset`:
          this is meant to facilitate modifying datasets used during tests.
  
      Returns
      -------
      pathlib.Path
          Full path to the json file created.
      """
      if json_file is None:
          json_file = (
              Path(bids_path)
              / "derivatives"
              / "sub-01"
              / "ses-01"
              / "func"
              / "sub-01_ses-01_task-main_run-01_space-MNI_desc-preproc_bold.json"
          )
      else:
          json_file = Path(bids_path) / json_file
  
      with open(json_file, "w") as f:
          json.dump(metadata, f)
  
      return json_file
  
imports: from __future__ import annotations
  import itertools
  import json
  import string
  from pathlib import Path
  import numpy
  import pandas
  import scipy.linalg
  import scipy.signal
  from nibabel import Nifti1Image
  from scipy.ndimage import binary_dilation
  from nilearn import datasets, image, maskers, masking
  from nilearn._utils import as_ndarray, logger
  from nilearn.interfaces.bids.utils import bids_entities, check_bids_label, create_bids_filename
  from nilearn.interfaces.fmriprep.tests._testing import get_legal_confound
label_desc: Use image node_id 15 for calling a global function with example usage: add_metadata_to_bids_dataset(bids_path, metadata, json_file) and returns: json_file