Search code examples
c#jsonjson.net

Get a specific nested JSON property using JObject


How do I get a specific nested property from a JSON using JObject?

For example i want to get the uri:

{
"embed": {
    "uri": "/presets/88930"

...


Solution

  • There's many ways to access the property you're interested in.

    Here's one:

        String jsonData = "{ 'embed': { 'uri': '/presets/88930'}}";
        var jObject = Newtonsoft.Json.Linq.JObject.Parse(jsonData);
        Console.WriteLine((string)jObject["embed"]["uri"]);