0

I want to load a mat-file in Python and convert it to a JSON format.

I can load it with loadmat-command but I can not convert it to JSON with the json.dumps command.

I create a Dash GUI. In this, I want to load a mat-file in a callback and save it global in a hidden DIV, so I don't have to load it new every time I need the mat-file data with loadmat which takes a lot of time. This is what i have tried:

import json

data = loadmat(path)     
data_json = json.dumps(Datensatz)

The error is:

Object of type bytes is not JSON serializable

FBruzzesi
  • 6,385
  • 3
  • 15
  • 37
Philipp Reis
  • 1
  • 1
  • 1
  • (`Datensatz` is a bit underspecified here, but I went to https://docs.scipy.org/doc/scipy/reference/generated/scipy.io.loadmat.html, got the test file they use in the example from https://github.com/chaoxia1/EIA/blob/master/dist/Main.app/Contents/Resources/lib/python2.7/scipy/io/matlab/tests/data/testdouble_7.4_GLNX86.mat, and `json.dumps(scipy.io.loadmat("testdouble_7.4_GLNX86.mat")["testdouble"].tolist())` just worked fine) – tevemadar May 03 '19 at 11:09
  • Btw, for the error message, there is an exact hit too, https://stackoverflow.com/questions/44682018/typeerror-object-of-type-bytes-is-not-json-serializable – tevemadar May 03 '19 at 11:12

0 Answers0