4 ms·
Exactly this. If you didn't do a compilers class and you want a simple language to play around with for lexing/parsing, JSON works great. Here's the core of a
by chucksmash 7y ago
Exactly this.
If you didn't do a compilers class and you want a simple language to play around with for lexing/parsing, JSON works great. Here's the core of a probably correct JSON lexer, albeit a super inefficient one, that I whipped up in <110 lines of Python a few years ago out of curiosity[1].
By comparison, check out the state machine transitions at the heart of the cpython implementation of the csv module[2]. It's not really a fair comparison (my JSON lexer is written in Python and uses regexes, the csv parser is written in C and does not use regexes) but even ignoring how nicely the csv parser handles different csv dialects, I still find it strictly more complex.
[1]: https://github.com/chucksmash/jsonish/blob/master/jsonish/tokens.py https://github.com/chucksmash/jsonish/blob/master/jsonish/to...
[2]: https://github.com/python/cpython/blob/41c57b335330ff48af098d47e379e0f9ba09d233/Modules/_csv.c#L591 https://github.com/python/cpython/blob/41c57b335330ff48af098...
- jstimpfle 7y agoYou misread me as well. I'm not saying that CSV is a good format. It's not, because it is ill-specified. All I'm saying is that flat database tuples are even easier to parse than JSON (which is nested, so requires a runtime stack). It was a total side note (in parentheses!). My main argument is that JSON is a mess to validate.