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 Jun 7

10 Things I Regret About Node.js

Photo courtesy of flickr user Trygve Lie. The creator of Node JS, Ryan Dahl, r...

READ POST
Alexandru Bucur
Programmer, Manager and a jack of all trades. Making things work since the dawn of time.
More from @coolgoose
Static / Fixed filenames for generated vue-cli builds
#beginners #vue #javascript #buildtools
Quick and easy way of counting UTF-8 characters in Javascript
#javascript #beginners #vue #react
Trending on dev.to
The Inspiration API: A project built with Scala & Play Framework
#scala #java #play #beginners
My Visual Studio Code Setup
#webdev #beginners #texteditor #vscode
Extendable heroes
#bash #modular #beginners
Quick Tip: Write an HTTP server in Dart πŸ’»
#tips #dart #http #beginners
Developing APIs using Actor model in ASP.NET Core
#aspnetcore #dotnetcore #csharp #dotnet
The Shell Introduction I Wish I Had
#shell #productivity #beginners #bash
Controlled number input with Floats in Elm
#elm #beginners #input #number
Log and Exponential for Programmers
#explainlikeimfive #beginners #algorithms