Skip to content

Commit

Permalink
Merge pull request #1938 from effigies/fix/load-json-eagerly
Browse files Browse the repository at this point in the history
FIX: Load JSON contents into context eagerly
  • Loading branch information
rwblair authored Apr 19, 2024
2 parents bc15afc + cfffe5c commit dc61d0f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
19 changes: 13 additions & 6 deletions bids-validator/src/schema/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export class BIDSContext implements Context {
datatype: string
modality: string
sidecar: object
json: object
columns: ColumnsMap
associations: ContextAssociations
nifti_header?: ContextNiftiHeader
Expand All @@ -87,15 +88,10 @@ export class BIDSContext implements Context {
this.modality = ''
this.sidecar = {}
this.columns = new ColumnsMap()
this.json = {}
this.associations = {} as ContextAssociations
}

get json(): Promise<Record<string, any>> {
return this.file
.text()
.then((text) => JSON.parse(text))
.catch((error) => {})
}
get path(): string {
return this.file.path
}
Expand Down Expand Up @@ -193,12 +189,23 @@ export class BIDSContext implements Context {
return
}

async loadJSON(): Promise<void> {
if (this.extension !== '.json') {
return
}
this.json = await this.file
.text()
.then((text) => JSON.parse(text))
.catch((error) => {})
}

async asyncLoads() {
await Promise.allSettled([
this.loadSidecar(),
this.loadColumns(),
this.loadAssociations(),
this.loadNiftiHeader(),
this.loadJSON(),
])
}
}
5 changes: 2 additions & 3 deletions bids-validator/src/summary/summary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,8 @@ export class Summary {
}

if (context.extension === '.json') {
const parsedJson = await context.json
if ('TaskName' in parsedJson) {
this.tasks.add(parsedJson.TaskName)
if ('TaskName' in context.json) {
this.tasks.add(context.json.TaskName as string)
}
}
if (context.modality) {
Expand Down

0 comments on commit dc61d0f

Please sign in to comment.