I am migrating from Json.NET - Newtonsoft to the new System.Text.Json.
In the former source, JObject
had the Add
method, however I cannot find a similar function for JsonElement
.
How would be the way to add a pair to the json object?
Asked
Active
Viewed 91 times
0
-
1If you look at https://stackoverflow.com/questions/58271901/converting-newtonsoft-code-to-system-text-json-in-net-core-3-whats-equivalent/58273914#58273914 it says that you can't edit the JSON data you get from `JsonDocument`. – Progman Feb 01 '20 at 10:27
-
`JsonDocument` and `JsonElement` are read-only in .Net 3.1. As an alternative you could consider deserializing to a partial data model + extension data attribute as shown in [Operation is not valid due to the current state of the object (System.Text.Json)](https://stackoverflow.com/a/59731594/3744182) or [Modifying a JSON file using System.Text.Json](https://stackoverflow.com/a/59001666/3744182). Beyond those suggestions could you share a [mcve] showing what modification you are trying to make? – dbc Feb 02 '20 at 02:11