❔ 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
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 placeyeah 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 😅
I dont think either Newtonsoft.Json nor STJ have functionality for that, so you are unfortunately out of luck here 🙁
Unless you write your own parser, no can do I'm afraid
If you know that all it's missing is closing brackets, treat the JSON as a string and add closing brackets until deserialization works
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.