Repository: bids-standard/pybids

Issue:
unclear validation error with dataset_description.json
A couple people have posted asking why their datasets could not be read (through fmriprep or mriqc), since the error message did not indicate which file was not formatted correctly.

example error message
```
json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 1 column 2 (char 1)
```

- example 1: https://neurostars.org/t/fmriprep1-2-3-jsondecode-error-expecting-value/3352
- example 2: https://neurostars.org/t/week-8-quiz-question-10/18410

Discussion:

Patch:
diff --git a/bids/layout/validation.py b/bids/layout/validation.py
index 463058ed..05b0278e 100644
--- a/bids/layout/validation.py
+++ b/bids/layout/validation.py
@@ -79,9 +79,21 @@ def validate_root(root, validate):
         else:
             description = None
     else:
-        with open(target, 'r', encoding='utf-8') as desc_fd:
-            description = json.load(desc_fd)
+        try:
+            with open(target, 'r', encoding='utf-8') as desc_fd:
+                description = json.load(desc_fd)
+        except json.JSONDecodeError:
+            description = None
         if validate:
+
+            if description is None:
+                raise BIDSValidationError(
+                    "'dataset_description.json' is not a valid json file."
+                    " There is likely a typo in your 'dataset_description.json'."
+                    "\nExample contents of 'dataset_description.json': \n%s" %
+                    json.dumps(EXAMPLE_BIDS_DESCRIPTION)
+                )
+            
             for k in MANDATORY_BIDS_FIELDS:
                 if k not in description:
                     raise BIDSValidationError(


Test patch:
diff --git a/bids/layout/tests/test_layout.py b/bids/layout/tests/test_layout.py
index d3196fb9..c48ee599 100644
--- a/bids/layout/tests/test_layout.py
+++ b/bids/layout/tests/test_layout.py
@@ -53,6 +53,17 @@ def test_layout_repr(layout_7t_trt):
     assert "Subjects: 10 | Sessions: 20 | Runs: 20" in str(layout_7t_trt)
 
 
+def test_invalid_dataset_description(tmp_path):
+    shutil.copytree(join(get_test_data_path(), '7t_trt'), tmp_path / "7t_dset")
+    (tmp_path / "7t_dset" / "dataset_description.json").write_text(
+        "I am not a valid json file"
+    )
+    with pytest.raises(BIDSValidationError) as exc:
+        BIDSLayout(tmp_path / "7t_dset")
+
+    assert "is not a valid json file" in str(exc.value)
+
+
 def test_layout_repr_overshadow_run(tmp_path):
     """A test creating a layout to replicate #681."""
     shutil.copytree(join(get_test_data_path(), '7t_trt'), tmp_path / "7t_trt")