Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8716047
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:59:08+00:00 2026-06-13T05:59:08+00:00

I am using NewtonSoft Json.NET library for parsing JSON files in a .NET app.

  • 0

I am using NewtonSoft Json.NET library for parsing JSON files in a .NET app.
What I need to do is to pass the name of a node, and get the node if it exists, regardless of their level which is unknown beforehand.

For instance in a file:

string json = @"{
  ""Name"": ""Apple"",
  ""Expiry"": new Date(1230422400000),
  ""Price"": 3.99,
  ""ATest"": {
    ""MyTest"":
    [
       ""blah"",
       ""blah""
    ]
  }
}";

Is there a way to just use the value "MyTest" to fetch that node without having to know the parent’s name like jObject["ATest"]["MyTest"][0]?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T05:59:09+00:00Added an answer on June 13, 2026 at 5:59 am

    AFAIK there’s no XPath-like query syntax for JToken / JObject, but you can make one fairly easily – see code below.

    public static class StackOverflow_13033174
    {
        public static void Test()
        {
            string json = @"{ 
                              ""Name"": ""Apple"", 
                              ""Expiry"": new Date(1230422400000), 
                              ""Price"": 3.99, 
                              ""ATest"": { 
                                ""MyTest"": 
                                [ 
                                   ""blah"", 
                                   ""blah"" 
                                ] 
                              } 
                            }";
    
            JObject jo = JObject.Parse(json);
            JToken myTest = jo.Descendants()
                .Where(t => t.Type == JTokenType.Property && ((JProperty)t).Name == "MyTest")
                .Select(p => ((JProperty)p).Value)
                .FirstOrDefault();
            Console.WriteLine(myTest);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using Newtonsoft's JSON.NET library to serialize some objects. In particular, I want
I'm working on a .NET 2.0 C# project using the Newtonsoft.JSON library. When i
I'm using Newtonsoft JSON.NET 4.5r7 in an MVC4 non-api project. Below I rename id
Currently I am using the terrific Linq 2 Json.net (by newtonsoft), which is a
I'm using the Newtonsoft JSON.NET package to deserialize my responses. This is a sample
I have a working application using Json.NET (newtonsoft) as a custom serializer. Currently I'm
Using JSON.Net, of the following 5 tests, the first and last pass while the
I am using the Newtonsoft JSon c# plugin. I jave a JArray {data:[{name:Wesley 1,id:616611941},{name:Wesley
I am using Newtonsoft.Json .Net for 4.0 for this project Parent class: public class
I am using Newtonsoft's Json.NET to deserialize a JSON string: var output = JsonConvert.DeserializeObject<dynamic>({

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.