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));

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)));
Did you find this post useful? Show some love!
Classic DEV Post from Dec 12 '17

Changelog: Site-wide design changes and a few other goodies

Whenever a website changes its design, there's bound to be mixed feelings. But ...

READ POST
Follow @ben to see more of their posts in your feed.
Alexandru Bucur
Programmer, Manager and a jack of all trades. Making things work since the dawn of time.
More from @coolgoose
How to get the user id after registering an user in ASP .NET Core Identity
#beginners #aspnetcore #netcore #csharp
Simple JSON API ASP .NET Core Error handling class
#csharp #aspnetcore #netcore #beginners
Trending on dev.to
A Github's search engine for OSS contributors wannabe
#beginners #opensource #react #showdev
Explain Higher Order Component(HOC) in React.js like I'm five
#explainlikeimfive #beginners
Even Though She Was Bad At Math, She Coded
#shecoded #beginners #webdev
How programming helps solving your real world problem
#productivity #career #programming #beginners
Using the Strategy Pattern (Examples in C#)
#architecture #designpatterns #oop #csharp
I asked my first StackOverflow question
#discuss #beginners #javascript
How to Start and Finish Any Web App Project
#beginners #webdev #flask #productivity
Web Servers Explained by Running a Microbrewery
#tutorial #beginners #webdev