News for hackers. Stuff that matters.
Re:Never use a dependency that you could replace with an aft... by Izkata on Tuesday August 11, 2020 @04:05PM (#24125349)
Your example is more apt than intended: That's not valid json, which only allows string keys. If you use a library it'll either barf now or later when they fix it, so if you're forced to work with an API like that and can't change it, a custom parser is really the only way to go.
Re:Never use a dependency that you could replace with an aft... by JackFr on Tuesday August 11, 2020 @04:49PM (#24125809)
Well the good libraries have option flags that will allow you to handle JSON as found in the wild.
Re:Never use a dependency that you could replace with an aft... by majewsky on Tuesday August 11, 2020 @06:13PM (#24126641)
That's not JSON, though. It's absolutely something else. Maybe a JS snippet. Maybe YAML. Definitely not JSON, though.

(Some JSON libraries do have option flags, but usually it's about whether, during deserializing into a known type, unknown fields are an error or silently ignored. Or whether C-style comments are an error or considered as whitespace.)

Re:Never use a dependency that you could replace with an aft... by JackFr on Tuesday August 11, 2020 @07:43PM (#24127233)
It may not be JSON but it’s out there in the wild. A lot.

Let’s say I’m scraping a website. I can:

1) complain to the owner that “it’s not JSON”.

2) write a parser for a syntax that has no spec, (it’s not JSON, but it sure looks an awful lot like JSON with unquoted keys.)

or

3) Set ALLOW_UNQUOTED_FIELD_NAMES to true in the Jackson library.

Re:Never use a dependency that you could replace with an aft... by Izkata on Tuesday August 11, 2020 @11:38PM (#24128388)
> Maybe a JS snippet.

While acceptable, also misleading: JS only does string keys, but unlike JSON it'll convert whatever it's given into strings. Not a problem most of the time, since it'll do the same conversion for both accessing and setting, but good to be aware of if you're doing something like iterating Object.keys()

Re:Never use a dependency that you could replace with an aft... by jimmynest on Wednesday August 12, 2020 @12:14PM (#24133530)
I use https://jsonformatter.org/json-parser sometime to parse json and to validate.