4 ms·
Parsing JSON using 'cut' and 'awk' and 'sed' sounds like the jankiest thing ever. Sure, maybe you get it working, after much pain. Then someone decides to form
by ekidd 3y ago
Parsing JSON using 'cut' and 'awk' and 'sed' sounds like the jankiest thing ever.
Sure, maybe you get it working, after much pain. Then someone decides to format your input JSON a bit differently, and everything fails catastrophically.
This is the same problem described in the infamous answer "You can't parse [X]HTML with regex":
https://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags https://stackoverflow.com/questions/1732348/regex-match-open...
(Now, if you've been caught in a time-travel accident, and if you must parse JSON using classic Unix tools, consider using lex and yacc. They are sufficiently powerful to do the job correctly.)
- deleted 3y ago[deleted]
- zoky 3y agoJSON is a particularly bad example, given that most of the commonly used scripting languages have standard libraries to parse JSON into a native data structure.
- fragmede 3y agoRaw JSON, absolutely. I usually use jq -C plus indexing into the dict but then sed/awk/grep (rg) do just fine.