How to import a JSON file into MATLAB programatically?
11,270
As of version 2016b, Matlab has integrated json support.
See: https://www.mathworks.com/help/matlab/ref/jsondecode.html
In short, you do:
jsonData = jsondecode(fileread('file.json'));
Author by
Adam
Updated on June 04, 2022Comments
-
Adam almost 2 years
I am trying to load my data from a JSON file into MATLAB that is delimited with
,
. The format of my data is as follows:{"created_at": "Mon Oct 27 20:35:47 +0000 2014", "tweet": "Silver Finished Up, Gold, Copper, Crude Oil, Nat Gas Down - Live Trading News http://t.co/jNLTUIgHwA", "id": 526834668759285761, "sentiment": "negative"} {"created_at": "Mon Oct 27 20:36:21 +0000 2014", "tweet": "Gold, Silver slips on lacklustre demand- The Economic Times http://t.co/Jd5Tn9ctfX", "id": 526834810300289024, "sentiment": "negative"}
How would I do so?
-
Adam over 9 yearswhen calling the function What parameters must i specify ?
-
Adam over 9 yearswhat does varargin refer to ?
-
Adam over 9 yearsUndefined function or variable 'varargin2struct'. Error in loadjson (line 61) opt=varargin2struct(varargin{:});
-
klurie over 9 yearsvarargin allows you to have variable input arguments. I'm attaching the file I used so you can check if it's your file or something else...
-
Adam over 9 yearsyh thats fine but what parameter should i pass as varargin
-
klurie over 9 yearsYou should use the function call I provided: tweet_info = loadjson(FILE_NAME_WITH_PATH). THere should be no need for additional arguments to the function.