Newtonsoft.Json
Newtonsoft.Json copied to clipboard
Support freezing a JToken
I'd like to propose the ability to "freeze" a JToken
. A frozen JToken
is essentially read-only; any attempt to change one of its properties results in an InvalidOperationException
.
- The term "a
JToken
" refers to any instance of a class derived fromJToken
. - When a
JToken
is initially created, it is not frozen. - When a
JToken
is frozen, all children of theJToken
are frozen as well.
No changes would be made to any current public API.
I would be happy to implement this functionality and send a pull request if you like the idea.
This is a little easier now that there is JsonLoadSettings. Could add a flag to that that loaded tokens should be frozen.
Any news on this? I just stumbled into a problem which I could solve nicely with immutable JObjects
Any update with this one?
This feature would be useful for records and other immutable types.
Any news on this ? JObject immutability would be incredibly usefull also for performances reasons, in all those scenarios where a datamodel represented as JObject must be passed to multiple consumers, but it must be ensured that such consumers don't alter it. Now the only way to obtain this, is to pass the source JSON STRING and parse it every time inside the logics of every consumer, which is a huge waste of CPU and RAM.
I'm pretty sure that there will be no new features in NSJ since the project is entirely in frozen state. MS has switched to STJ and all development is happening there.
How about to use DeepClone method ?