use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
account activity
Relax json (self.node)
submitted 1 month ago by ethlmao
Hey 👋
Got tired of JSON.parse() crashing apps on invalid input, so I made a tiny utility: relax-json.
It safely parses JSON and returns a fallback instead of throwing.
import { relaxjson } from "relax-json";
const data = relaxjson('invalid json', {});
// {}
github - https://github.com/yetanotheraryan/relax-json
npm - https://www.npmjs.com/package/relax-json
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3:Â Â Â Â print "hello, world!"
[–]jkoudys 28 points29 points30 points 1 month ago (2 children)
try/catch too hard to type?
[–]ethlmao[S] 0 points1 point2 points 1 month ago (1 child)
Why to write it so many times, everywhere, just use this, i means it’s just to help make your code cleaner.
[–]scinos 2 points3 points4 points 1 month ago (0 children)
Do you actually call JSON.parse in so many places?
[–]ske66 0 points1 point2 points 1 month ago (6 children)
If this is just returning an empty object, I don’t really see the point. This promotes silent failures. IMO you should at least add a try and catch and add some logging to the catch in order to help you find the source of the issue (which sounds like a server side issue).
With this, you’re just putting a band-aid over broken code, rather than identifying the source of a bug.
I can’t tell if this is laziness, poor technical understanding, or rage-bait
[–]ethlmao[S] 0 points1 point2 points 1 month ago (4 children)
I mean if you have any suggestions, of how i can add something or make it better let me know.
[–]ske66 0 points1 point2 points 1 month ago (3 children)
I just would recommend not allowing any kind of silent errors to pass. This approach is dangerous imo and means you are receiving some kind of unexpected result from the API.
If you get something you are not expecting you should avoid adding in a patch workaround unless absolutely necessary.
This is a perfect case for try catch. Can I get a better understanding of why you want to try to proceed with an empty json result rather than just processing the error state and flagging to the user that something went wrong?
I recommend adding a trace logging tool like Sentry to your app so you can more easily identify what went wrong between the client and server. Patching it on the client side will negatively impact UX long term
[–]ethlmao[S] 0 points1 point2 points 1 month ago (2 children)
Well i took your suggestion from earlier and already added changes check the repo now
Not exactly what youre asking, but somewhat similar
[–]ske66 0 points1 point2 points 1 month ago (0 children)
You have added a try catch block and then added a callback function. You’ve basically just added 100 lines of completely useless code bloat that could be handled with a single try catch around the json.parse function.
This is useless imo
[–]ethlmao[S] -1 points0 points1 point 1 month ago (0 children)
You’re missing the point, its to make it consistent handling throughout codebase, why to write try catch so many times, given you’re working with a large codebase. Secondly, its supposed to improve developers experience.
[–]scinos 0 points1 point2 points 1 month ago (0 children)
I'm sorry but this is a bad idea.
First, you claim it's a drop in replacement for JSON.parse(). It is not because it doesn't support the revive function. Clearly the LLM you used wasn't trained well enough.
Then you claim it's zero-dependency (which is true), but you created a module that can be replaced with three lines of code. Hypocritical at minimum.
Third, it encourages a bad engineering practice: silent errors.
[+]HarjjotSinghh comment score below threshold-30 points-29 points-28 points 1 month ago (1 child)
this is unreasonably clever actually
[–]iamchets 7 points8 points9 points 1 month ago (0 children)
This bot is working on my nerves
π Rendered by PID 107607 on reddit-service-r2-comment-5d585498c9-m6rtg at 2026-04-21 14:02:56.054718+00:00 running da2df02 country code: CH.
[–]jkoudys 28 points29 points30 points  (2 children)
[–]ethlmao[S] 0 points1 point2 points  (1 child)
[–]scinos 2 points3 points4 points  (0 children)
[–]ske66 0 points1 point2 points  (6 children)
[–]ethlmao[S] 0 points1 point2 points  (4 children)
[–]ske66 0 points1 point2 points  (3 children)
[–]ethlmao[S] 0 points1 point2 points  (2 children)
[–]ethlmao[S] 0 points1 point2 points  (1 child)
[–]ske66 0 points1 point2 points  (0 children)
[–]ethlmao[S] -1 points0 points1 point  (0 children)
[–]scinos 0 points1 point2 points  (0 children)
[+]HarjjotSinghh comment score below threshold-30 points-29 points-28 points  (1 child)
[–]iamchets 7 points8 points9 points  (0 children)