C
C#β€’13mo 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
HimmDawgβ€’13mo 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
44β€’13mo 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
HimmDawgβ€’13mo ago
I dont think either Newtonsoft.Json nor STJ have functionality for that, so you are unfortunately out of luck here πŸ™
Angius
Angiusβ€’13mo ago
Unless you write your own parser, no can do I'm afraid
Mordeo
Mordeoβ€’13mo 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
Accordβ€’13mo 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.