Reputation: 93
I have a json object and I am trying to parse to object in MATLAB to into a cell array however when I parse the filename it throughs this error...
`Error using loadjson>error_pos (line 431) JSONparser:invalidFormat: String starting with " expected at position 18767: nt": "neutral",} {"created_at": "Mon
Error in loadjson>parseStr (line 301) error_pos('String starting with " expected at position %d');
Error in loadjson>parse_object (line 169) str = parseStr(varargin{:});
Error in loadjson (line 66) data{jsoncount} = parse_object(opt);`
Some sample data in the JSON object is:
{"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"}
{"created_at": "Mon Oct 27 20:36:26 +0000 2014", "tweet": "Price of Gold is $1225.7 on 10-27-2014 16:36:13. - http://t.co/yYP5ubMFEA", "id": 526834831209291777, "sentiment": "positive"}
{"created_at": "Mon Oct 27 20:36:30 +0000 2014", "tweet": "Diwali Spurs Uptick In Physical Gold Demand - Barclays - http://t.co/nxIteCvusL", "id": 526834849563172864, "sentiment": "positive"}
{"created_at": "Mon Oct 27 20:37:50 +0000 2014", "tweet": "Price of Gold is $1225.8 on 10-27-2014 16:37:12. - http://t.co/yYP5ubMFEA", "id": 526835183639883776, "sentiment": "positive"}
{"created_at": "Mon Oct 27 20:38:03 +0000 2014", "tweet": "#Platinum/#Gold #ratio #trading 1.026, so 1 oz of #Platinum is $32 more than 1 oz of #Gold - https://t.co/EkERU2sQus", "id": 526835236269998080, "sentiment": "positive"}
Can anyone pass on their thoughts on the matter ?
Upvotes: 0
Views: 668
Reputation: 104514
You didn't provide us the entire picture. The JSON structure before the {"created_at":...
seems to be missing a double quotation mark. There also seems to be an unnecessary comma at the end. This should probably go outside of the curly braces. This also makes sense because I'm assuming that we haven't reached the end of your JSON file yet, and you need to use commas to separate between the different fields.
As such, locate the following line:
...nt": "neutral",}
Change it to this:
..."nt": "neutral"},
FWIW, the error message is quite clear. It was expecting a "
literal, but it is missing. Also, Daniel provided a great tool in his comment to you called JSONLint. Use the URL to validate whether or not your JSON structure is valid.
Upvotes: 1