C
C#2y ago
44

❔ Newtonsoft json parse while ignoring issues

Hi all, sorry if I am an idiot but is there a way to make newtonsoft import broken json, and import what it can? Right now my json somethimes is cut off but is still usable after adding the right brackets.
6 Replies
HimmDawg
HimmDawg2y ago
It cannot import broken json. What I'd do is, when deserializing json, you are able to pass JsonSerializerSettings. In those settings, there is a Property Error. This is an EventHandler, so you can just subscribe to it. And in there, I'd try to set the brackets, as you said. Well, given that you 100% know which brackets to insert and where. And then try it again But then again, try to get clean json in the first place
44
44OP2y ago
yeah I try to always get clean JSOn but it is from a LLM so that sometimes just cuts off the json, but I cannot preprogram so I was hoping it had some functionality for it 😅
HimmDawg
HimmDawg2y ago
I dont think either Newtonsoft.Json nor STJ have functionality for that, so you are unfortunately out of luck here 🙁
Angius
Angius2y ago
Unless you write your own parser, no can do I'm afraid
Mordeo
Mordeo2y ago
If you know that all it's missing is closing brackets, treat the JSON as a string and add closing brackets until deserialization works
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server