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

JSONToTable has problems #3869

Closed
TimGoll opened this issue May 31, 2019 · 12 comments
Closed

JSONToTable has problems #3869

TimGoll opened this issue May 31, 2019 · 12 comments

Comments

@TimGoll
Copy link

TimGoll commented May 31, 2019

Details & Steps to Reproduce

The function util.JSONToTable has problems with json files created with the windows text editor. Files created with notepad ++ work though

An easy way to test is by using util.TableToJSON and saving the output in a *.txt-file. Opening and edit it with notepad++ and you're still able to read and parse the file as a table. But once you open, edit and save it with the windows text editor, it stops working. Reading the file still works and a print shows, that it is read correct, but util.JSONToTable returns nil when passed the JSON string without any errors.

It seems like util.JSONToTable is not that robust to formating.

@willox
Copy link
Contributor

willox commented May 31, 2019

I can't reproduce this. Maybe it's the new version of Notepad Windows 10 is beginning to ship, it could be adding a BOM to the start of the file or something.

@TimGoll
Copy link
Author

TimGoll commented May 31, 2019

That's very strange, since multiple users on our server can confirm this issue
we're using the TTT gamemode if that matters

@willox
Copy link
Contributor

willox commented May 31, 2019

Show us the JSON file

@TimGoll
Copy link
Author

TimGoll commented May 31, 2019

https://steamcommunity.com/sharedfiles/filedetails/?id=1755840967 (now the correct link)
this addon creates the file in garrysmod/data/ctc/. I can post the file later today when I'm back home.

But the file does work. It only stops working when edited with the windows text editor

@TimGoll
Copy link
Author

TimGoll commented May 31, 2019

(I suspect it has something todo with the file ending or the line ends, since I know that the windows text editor behaves differently in this case than other editors)

@TimGoll
Copy link
Author

TimGoll commented May 31, 2019

Sorry, wrong addon! This one: https://steamcommunity.com/sharedfiles/filedetails/?id=1755840967

@willox
Copy link
Contributor

willox commented May 31, 2019

I can reproduce it with the CTC_DEFAULT table. I'll look into it a little more.

@willox
Copy link
Contributor

willox commented May 31, 2019

Yes, notepad is adding a BOM. Probably some automatic thing because of the text in the file. We can probably change JSONToTable to skip it without any issues.

@robotboy655
Copy link
Contributor

robotboy655 commented May 31, 2019

This is weird because new version removes the BOM mark by default, not adds it as far as I know.
Or you could just save the file without a BOM mark in the save dialog in newer version, or use np++, no reason not to.

@TimGoll
Copy link
Author

TimGoll commented May 31, 2019

it's no problem for me since I always use np++. But ther ewere a few users already that reported to me that the addon wasn't working since they used the windows text editor even though I have a warning at the top of the docu.

@robotboy655
Copy link
Contributor

Fixed, util.JSONToTable now skips the UTF-8 BOM mark.

@TimGoll
Copy link
Author

TimGoll commented May 31, 2019

nice, thank you!

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

3 participants