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!
DISCUSSION
Classic DEV Post from Apr 25

How do web developers/freelancers build websites in time?

How do web developers or freelancers build websites nowadays in time? From s...

READ POST
Follow @iandavid 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
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
Why Your Best Work is Hardest to Finish
#productivity #career #beginners
Setting up Windows Subsytem for Linux
#beginners
Binary and Hexadecimal: Part 2 - Conversions
#computerscience #basics #beginners
React router beginners guide
#react #javascript #beginners #webdev
MY Top 5 youtube channels (code version)
#youtube #dev #beginners
How to ask good questions as a developer
#beginners #devtips #learning #webdev
Jelly Fin: Open Source From Scratch, What I've Learned So Far
#jellyfin #opensource #beginners #mentoring
My Experiences in a Coding Bootcamp for 2 Months
#javascript #codingbootcamp #bootcamps #beginners