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'));
Share:
11,270
Adam
Author by

Adam

Updated on June 04, 2022

Comments

  • Adam
    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
    Adam over 9 years
    when calling the function What parameters must i specify ?
  • Adam
    Adam over 9 years
    what does varargin refer to ?
  • Adam
    Adam over 9 years
    Undefined function or variable 'varargin2struct'. Error in loadjson (line 61) opt=varargin2struct(varargin{:});
  • klurie
    klurie over 9 years
    varargin 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
    Adam over 9 years
    yh thats fine but what parameter should i pass as varargin
  • klurie
    klurie over 9 years
    You 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.