DEV Community

Alexandru Bucur
Alexandru Bucur

Posted on

2 2

JSON.NET append to existing key

A quick example for appending to an existing key in a JSON.NET object, since for me at least it wasn't clear in the documentation.

JObject myJson = new JObject(new JProperty("errors", new JObject()));

/// we can now reference it as follows just match the type

myJson["errors"].Value<JObject>().Add(new JProperty("title", title));
Enter fullscreen mode Exit fullscreen mode

Small update:

You can even add multiple entries to an JArray the same way

/// assuming errors is a JArray, this will automatically append new entries
ErrorReponse["errors"].Value<JArray>().Add(new JObject(new JProperty("title", title)));
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more