Live data from Hacker News

Parsing JSON is a Minefield

seriot.ch

61–70 of 301 posts

Re: Parsing JSON is a Minefield

#63
post #56
post #19

Earlier 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"}

Since when is in-band signalling a good idea? What if one of your configuration keys is named "comment"?

Re: Parsing JSON is a Minefield

#64
Now 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

#66
post #41

The page has been taken down for some reason (getting a 403). Google cache: http://webcache.googleusercontent.com/search?q=cache:8jVuBmx...

Works for me. Edit: But you are not alone. Elsewhere in the thread: https://news.ycombinator.com/item?id=12797032

Yep, looks like it was down only for a few minutes.

Re: Parsing JSON is a Minefield

#67

The page has been taken down for some reason (getting a 403). Google cache: http://webcache.googleusercontent.com/search?q=cache:8jVuBmx...

Too heavy CPU load.

Now I turned the PHP page into a static HTML one and it's back online.

Configuring web servers is a minefield :)

Re: Parsing JSON is a Minefield

#68
post #63
post #56

Earlier quoted context omitted.

How does json "not support comments"? {"comment":"default values for this object"}

Since when is in-band signalling a good idea? What if one of your configuration keys is named "comment"?

And what do you name your second comment?

Re: Parsing JSON is a Minefield

#69
post #52

> In conclusion, JSON is not a data format you can rely on blindly. That was definitely not my take-away from the article. More like "JSON is not a data format you can rely on blindly if you are using an esoteric edge-case and/or an alpha-stage parsing library." I haven't ever run into a single JSON issue that wasn't due to my own fat fingers or trying to serialize data that would have been better suited to something…

The sum totality of all the issues raised in that post is not an esoteric edge case, even if each individual element is an esoteric edge case. If you haven't encountered any of them in your real code yet, there's two basic possibilities. Either you aren't using JSON very hard at all... or you have encountered them and you just didn't realize it. You will, sooner or later. I'm not saying JSON is bad. Personally I thin…

JSON doesn't have an integer type, but it certainly supports integers. Within, obviously, implementation defined limits. I'm with you up to "if you need precision, avoid JSON". Actually JSON is fine for the kinds of precision most use cases require, and when it isn't, you probably know it.

Re: Parsing JSON is a Minefield

#70
post #32
post #14

Well, 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?

This was something I wondered about in these results: what's the definition of "crash"? Specifically, with the Rust libraries, I'm not sure if this means "the program panic'd" or "the program segfaulted", or something else. The former isn't ideal, but isn't the worst. The later would be much more worrysome.
Post reply on HN