r/programming • • Feb 25 '21

An Exploration of JSON Interoperability Vulnerabilities

https://labs.bishopfox.com/tech-blog/an-exploration-of-json-interoperability-vulnerabilities
128 Upvotes

39 comments sorted by

View all comments

33

u/headhunglow Feb 25 '21

Finally some real programming content on /r/programming! Great writeup! However, I'm wondering why any JSON parser would support comments?

26

u/evaned Feb 25 '21

Lots of things use JSON for configuration files and other things intended to be hand-written, as I'm sure you've noticed. Tools have been "updated" to support that use, which hugely benefits from comments, to the point of it turning a terrible language for that purpose into one that's usually merely mediocre.

As for why JSON is used there instead of INI or TOML something... well that I think mostly falls into "everything is terrible" category.

13

u/[deleted] Feb 25 '21

I think JSON is better than TOML for configuration purposes except for the fact that it often doesn't support comments and trailing commas (cough package.json) and it isn't clear when it does and when it doesn't. JSON5 solves that problem but isn't as widely supported.

TOML is ok, but it still has more weird quirks and is less obvious than JSON (but way better than YAML).

In particular the [[table]] syntax is very unintuitive, to the point that I still don't understand it. JSON arrays are blindingly obvious.

Another weirdness is that you can put a table in braces, but only if it is all on one line! Another thing JSON got right.

For all its limitations JSON is probably the best thing to come out of JavaScript. It got a lot right.

1

u/nigeltao Feb 26 '21

I think JSON is better than TOML for configuration purposes except for the fact that it often doesn't support comments and trailing commas

Funnily enough, I just posted this a few days ago: https://nigeltao.github.io/blog/2021/json-with-commas-comments.html

0

u/[deleted] Feb 26 '21

Isn't that exactly the same as VSCode's JSONC? It also doesn't solve the ambiguity problem unless he is advocating using a .jwcc extension. I wish the VSCode guys had used a .jsonc extension.

(And I wish done other guy hadn't also made a dumb format called JSONC.)

1

u/nigeltao Feb 26 '21

I have updated my blog post. No, it's not quite the same as Visual Studio's JSONC, because commas. Yes, I am advocating a .jwcc extension.

1

u/[deleted] Feb 26 '21

What about commas? They both support trailing commas.

1

u/nigeltao Feb 27 '21

Ah, I didn't know that. https://code.visualstudio.com/docs/languages/json#_json-with-comments doesn't mention commas at all. It only talks about comments.

In that case, I'm guessing that Visual Studio's JSONC is the same thing. I'd still prefer a .jwcc extension instead of .json, since it's not JSON.

1

u/[deleted] Feb 27 '21

Yeah bit of omission but it does. And yeah I just wish they used .jsonc.