> In conclusion, JSON is not a data format you can rely on blindly. What does HN suggest for configuration files (to be written by a human essentially)? I am looking at YAML and TOML. My experience with JSON based config files was horrible.
Lua was written for exactly this purpose, and I personally enjoy writing with it, so it would be my first choice in most cases.
Parsing JSON is a Minefield
91–100 of 301 posts
Re: Parsing JSON is a Minefield
#92Earlier quoted context omitted.
What about raise an exception?
Exceptions should only be used for exceptional cases. For a parser, bad input should be expected.
Re: Parsing JSON is a Minefield
#93Earlier quoted context omitted.
What about raise an exception?
Exceptions should only be used for exceptional cases. For a parser, bad input should be expected.
Re: Parsing JSON is a Minefield
#94Well, first and most obviously, if you are thinking of rolling your own JSON parser, stop and seek medical attention. Secondly, assume that parsing your input will crash, so catch the error and have your application fail gracefully. This is the number one security issue I encounter in "security audited" PHP. (The second being the "==" vs. "===" debacle that is PHP comparison.) As one example, consider what happens wh…
A parser should never crash on bad input. If it does, that's a serious bug that needs immediate attention, since that's at least a DoS vulnerability and quite likely something that could result in remote code execution. You definitely need to assume that the parser could fail , but that's different. Unless you're using "crash" in some way I'm not familiar with?
Re: Parsing JSON is a Minefield
#95Now the mess that is called JavaScript dates has crept into any system imaginable in the world. I can understand we needed to go for the lowest denominator but Crockford's card really could cram in another line with a date time string format.
Re: Parsing JSON is a Minefield
#96Wrote my own JSON parser ( https://github.com/MJPA/SimpleJSON ) a while ago... not sure how it's a minefield unless I'm missing something?
Did you read the post? The JSON standard(s) are very simple. But in practice this simplicity leads to a lot of edge cases. Very deeply nested structures, numbers that run on to infinity. The point of this post is testing various parsers against these malicious structures. See this image: http://seriot.ch/json/pruned_results.png
Re: Parsing JSON is a Minefield
#97Now the mess that is called JavaScript dates has crept into any system imaginable in the world. I can understand we needed to go for the lowest denominator but Crockford's card really could cram in another line with a date time string format.
Just use epoch or ISO1601.
Re: Parsing JSON is a Minefield
#98Earlier quoted context omitted.
> (b) it's an OK choice though I really think it's not an OK choice. A config file format that doesn't allow comments provides some of the worst possible UX. One of the nice things about config files is that normally they are self-documenting, explaining the meaning of the various directives and providing possible values. Without comments, you have to constantly switch between the documentation and the config file. A…
How does json "not support comments"? {"comment":"default values for this object"}
Re: Parsing JSON is a Minefield
#99Well, first and most obviously, if you are thinking of rolling your own JSON parser, stop and seek medical attention. Secondly, assume that parsing your input will crash, so catch the error and have your application fail gracefully. This is the number one security issue I encounter in "security audited" PHP. (The second being the "==" vs. "===" debacle that is PHP comparison.) As one example, consider what happens wh…
A parser should never crash on bad input. If it does, that's a serious bug that needs immediate attention, since that's at least a DoS vulnerability and quite likely something that could result in remote code execution. You definitely need to assume that the parser could fail , but that's different. Unless you're using "crash" in some way I'm not familiar with?
Re: Parsing JSON is a Minefield
#100There was a great article at some point that explained why 'be liberal in what you accept' is a very bad engineering practice in certain circumstances, such as setting a standard, because it causes users to be confused and annoyed when a value accepted by system A is subsequently not accepted by supposedly compatible system B. Leading to pointless discussions about what the spec 'intended' and subtle incompatibility.…
https://news.ycombinator.com/item?id=9824638
If not, perhaps one of these:
http://programmingisterrible.com/post/42215715657/postels-pr...
https://bitworking.org/news/There_are_no_exceptions_to_Poste...