Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<!--
A new scriv changelog fragment.

Uncomment the section that is right (remove the HTML comment wrapper).
For top level release notes, leave all the headers commented out.
-->

<!--
### Added

- A bullet item for the Added category.

-->
### Changed

- Raise error when json files are parsed and their root value is an array instead of object

<!--
### Fixed

- A bullet item for the Fixed category.

-->
<!--
### Deprecated

- A bullet item for the Deprecated category.

-->
<!--
### Removed

- A bullet item for the Removed category.

-->
<!--
### Security

- A bullet item for the Security category.

-->
<!--
### Infrastructure

- A bullet item for the Infrastructure category.

-->
7 changes: 6 additions & 1 deletion src/files/json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,14 @@ async function readJSONText(file: BIDSFile): Promise<string> {

export async function loadJSON(file: BIDSFile): Promise<Record<string, unknown>> {
const text = await readJSONText(file) // Raise encoding errors
let parsedText;
try {
return JSON.parse(text)
parsedText = JSON.parse(text)
} catch (error) {
throw { key: 'JSON_INVALID' } // Raise syntax errors
}
if (Array.isArray(parsedText)) {
throw { key: 'JSON_NOT_AN_OBJECT' }
}
return parsedText
}
4 changes: 4 additions & 0 deletions src/issues/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ export const bidsIssues: IssueDefinitionRecord = {
severity: 'error',
reason: 'Not a valid JSON file.',
},
JSON_NOT_AN_OBJECT: {
severity: 'error',
reason: 'Parsed json file contains an array as its root element and not an object.',
},
MISSING_DATASET_DESCRIPTION: {
severity: 'error',
reason: 'A dataset_description.json file is required in the root of the dataset',
Expand Down
Loading