code: def test_add_metadata_to_bids_derivatives_with_json_path(tmp_path):
      # bare bone smoke test
      target_dir = tmp_path / "derivatives" / "sub-02"
      target_dir.mkdir(parents=True)
      json_file = "derivatives/sub-02/sub-02_task-main_bold.json"
      json_file = add_metadata_to_bids_dataset(
          bids_path=tmp_path,
          metadata={"foo": "bar"},
          json_file=json_file,
      )
      assert json_file.exists()
      assert json_file.name == "sub-02_task-main_bold.json"
      with open(json_file) as f:
          metadata = json.load(f)
          assert metadata == {"foo": "bar"}
  
imports: from __future__ import annotations
  import json
  import numpy
  import pytest
  from nilearn._utils.data_gen import add_metadata_to_bids_dataset, create_fake_bids_dataset, generate_fake_fmri, generate_labeled_regions, generate_maps, generate_regions_ts
  from nilearn.image import get_data
label_desc: Use image node_id 2 for calling a global function with example usage: test_add_metadata_to_bids_derivatives_with_json_path(tmp_path) without return types