1

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
1
  • I do not think an ndarray can be saved into a json file, as it is. You could convert it to a list using my_array.tolist() and then store it to json. Commented Jul 25, 2018 at 13:23

1 Answer 1

11

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

it can be either json.load(f) or json.loads(f.read()). Load accepts file like object, loads accepts str or bytes
tried it , it shows: TypeError: expected string or buffer
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 file
"import json with open("package.json") as f: json.loads(f)"
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
|

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.