i have a problems with writing a list to JSON file, here s code:
import numpy as np
import json
filename = "sub-01_task-rest_bold.json"
with open(filename, 'r') as f:
niiMeta = json.load(f)
rTime = niiMeta.get("RepetitionTime")
nSlices = niiMeta.get("dcmmeta_shape")
imType = niiMeta.get("ImageType")
def numberofslices(n):
if "EPI" in imType and len(nSlices) == 4:
h = n[2]
return h
else:
return 0
def checktr(t):
if t >= 1000:
k = t*0.001
return k
else:
return t
def slicetime(tr, n):
tr = checktr(tr)
n = numberofslices(n)
lastslice = tr - tr/n
esti = np.linspace(0, lastslice, n)
return esti
addstc = slicetime(rTime, nSlices).tolist()
niiMeta["SliceTiming "] = addstc
with open(filename, 'w') as f:
json.dump(niiMeta, f, indent=4)
It work and creates new key with list, but it differs from original file: ORIGINAL:with horizontal line
OUTPUT:[with vertical line][2]
As you can see it have an tabs in list. Please help me to remove it.