Opening .json file

249 views (last 30 days)
Hi there, I am new at working with .json files and I am trying to open the data from an IMU. I using the code below, however, when using the jsondecode function I keep getting the following error "Error using jsoncode JSON syntaz error at line 2, column 1 (character 634) extra text". The line and column and character differ depending on the file, but cannot find what ios the "extra text". Any ideas how to solve the problem?
many thanks
eduardo
fileName = '20201108T225105Z_180230000291_gyro_stream.json'; % filename in JSON extension
fid = fopen(fileName); % Opening the file
raw = fread(fid,inf); % Reading the contents
str = char(raw'); % Transformation
fclose(fid); % Closing the file
data = jsondecode(str); % Using the jsondecode function to parse JSON from string

Accepted Answer

Manas Meena
Manas Meena on 11 Nov 2020
The most common cause for the extra text error is additional “” signs in the json string. Please check the formatting of the jsoncode. You can also try using the fileread function instead of fread and since you are not providing the full path please add a check before fid to make sure that it is valid.
fileName = 'filename.json'; % filename in JSON extension
str = fileread(fileName); % dedicated for reading files as text
data = jsondecode(str); % Using the jsondecode function to parse JSON from string
The following link provides the information for decoding or creating JSON formatted text.
  1 Comment
Luis Eduardo Cofré Lizama
Thansk Manas, unfortunately couldnt test your suggestion as the files provided by the device I was using are actuallly corrupted and that is problem. The company, I think, is solving the issue.
Cheers

Sign in to comment.

More Answers (0)

Products


Release

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!