This .json file contains record from ECG machine. The file format looks like this:
[-0.140625,-0.15234375,-0.15234375,...,-0.19335937499999997,0 ]
However, when I try to use this code, it shows an error
def load_tester(path):
dataset = '{"fruits": }'
data = json.loads(path)
print(data)
return(np.asarray(nt))
this is the error:
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
I want to save that file into numpy array and become as same as the format that the json uses.
emartinelli
1,04715 silver badges28 bronze badges
asked Jul 25, 2018 at 12:49
user5648046user5648046
1 Answer 1
You are trying to load json usign a file name, but not data that is in the file
def load_tester(path):
with open(path) as f:
data = json.load(f)
print(data)
return np.asarray(data)
answered Jul 25, 2018 at 12:53
6 Comments
Fuxi
it can be either
json.load(f)
or json.loads(f.read())
. Load accepts file like object, loads accepts str or bytesdilkash
tried it , it shows: TypeError: expected string or buffer
Fuxi
Can you show how do you run it, please? The question mentions a json file (I assumed path is a file path to this file) with content being a list of floats. I tested it with
load_tester('x.json')
where x.json
is a local filedilkash
"import json with open("package.json") as f: json.loads(f)"
Fuxi
Please read my comment about load/loads again. Just use load in your code and you will be fine. Atm you're trying to loads (that expects a string) but giving a file object as input
|
lang-py
ndarray
can be saved into a json file, as it is. You could convert it to alist
usingmy_array.tolist()
and then store it to json.