Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

loadjson sensitive to tabs in whitespace? #30

Closed
lebedov opened this issue Dec 27, 2016 · 2 comments
Closed

loadjson sensitive to tabs in whitespace? #30

lebedov opened this issue Dec 27, 2016 · 2 comments

Comments

@lebedov
Copy link

lebedov commented Dec 27, 2016

It seems that the presence of tabs in a JSON file can cause loadjson() to load certain files differently. Using revision f8def3d of jsonlab with either MATLAB R2016a or Octave 4.2.0, loading foo.json from files.zip (which contains tabs) using data = loadjson('foo.json') causes data.a.b.c to be created as a cell array, while loading bar.json (which contains only spaces) causes data.a.b.c to be created as a matrix. Shouldn't c always be created as a matrix regardless of the whitespace?

@fangq fangq closed this as completed in ba75691 Jan 2, 2017
@fangq
Copy link
Member

fangq commented Jan 2, 2017

@lebedov, thanks for reporting this issue. I debugged loadjson with both of your provided json files, and found the issue was caused by sscanf when parsing trailing whitespace in an array construct. for example:

[obj, count, errmsg, nextidx]=sscanf(sprintf('1,2,3'),'%f,',[1,inf])

and

[obj, count, errmsg, nextidx]=sscanf(sprintf('1,2,3\t'),'%f,',[1,inf])

return different errmsg and nextidx outputs. I added one line to remove the trailing white space, and now both inputs generate the same array. let me know if there is any problem with this fix.

@lebedov
Copy link
Author

lebedov commented Jan 3, 2017

Looks good so far. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants