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

  • SEARCH
  • Home
  • 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 6618667
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:51:52+00:00 2026-05-25T20:51:52+00:00

I’m trying to use JsonPath for .NET ( http://code.google.com/p/jsonpath/downloads/list ) and I’m having trouble

  • 0

I’m trying to use JsonPath for .NET (http://code.google.com/p/jsonpath/downloads/list) and I’m having trouble finding an example of how to parse a Json string and a JsonPath string and get a result.

Has anyone used this?

  • 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-05-25T20:51:53+00:00Added an answer on May 25, 2026 at 8:51 pm

    The problem you are experiencing is that the C# version of JsonPath does not include a Json parser so you have to use it with another Json framework that handles serialization and deserialization.

    The way JsonPath works is to use an interface called IJsonPathValueSystem to traverse parsed Json objects. JsonPath comes with a built-in BasicValueSystem that uses the IDictionary interface to represent Json objects and the IList interface to represent Json arrays.

    You can create your own BasicValueSystem-compatible Json objects by constructing them using C# collection initializers but this is not of much use when your Json is coming in in the form of strings from a remote server, for example.

    So if only you could take a Json string and parse it into a nested structure of IDictionary objects, IList arrays, and primitive values, you could then use JsonPath to filter it! As luck would have it, we can use Json.NET which has good serialization and deserialization capabilities to do that part of the job.

    Unfortunately, Json.NET does not deserialize Json strings into a format compatible with the BasicValueSystem. So the first task for using JsonPath with Json.NET is to write a JsonNetValueSystem that implements IJsonPathValueSystem and that understands the JObject objects, JArray arrays, and JValue values that JObject.Parse produces.

    So download both JsonPath and Json.NET and put them into a C# project. Then add this class to that project:

    public sealed class JsonNetValueSystem : IJsonPathValueSystem
    {
        public bool HasMember(object value, string member)
        {
            if (value is JObject)
                    return (value as JObject).Properties().Any(property => property.Name == member);
            if (value is JArray)
            {
                int index = ParseInt(member, -1);
                return index >= 0 && index < (value as JArray).Count;
            }
            return false;
        }
    
        public object GetMemberValue(object value, string member)
        {
            if (value is JObject)
            {
                var memberValue = (value as JObject)[member];
                return memberValue;
            }
            if (value is JArray)
            {
                int index = ParseInt(member, -1);
                return (value as JArray)[index];
            }
            return null;
        }
    
        public IEnumerable GetMembers(object value)
        {
            var jobject = value as JObject;
            return jobject.Properties().Select(property => property.Name);
        }
    
        public bool IsObject(object value)
        {
            return value is JObject;
        }
    
        public bool IsArray(object value)
        {
            return value is JArray;
        }
    
        public bool IsPrimitive(object value)
        {
            if (value == null)
                throw new ArgumentNullException("value");
    
            return value is JObject || value is JArray ? false : true;
        }
    
        private int ParseInt(string s, int defaultValue)
        {
            int result;
            return int.TryParse(s, out result) ? result : defaultValue;
        }
    }
    

    Now with all three of these pieces we can write a sample JsonPath program:

    class Program
    {
        static void Main(string[] args)
        {
            var input = @"
                  { ""store"": {
                        ""book"": [ 
                          { ""category"": ""reference"",
                                ""author"": ""Nigel Rees"",
                                ""title"": ""Sayings of the Century"",
                                ""price"": 8.95
                          },
                          { ""category"": ""fiction"",
                                ""author"": ""Evelyn Waugh"",
                                ""title"": ""Sword of Honour"",
                                ""price"": 12.99
                          },
                          { ""category"": ""fiction"",
                                ""author"": ""Herman Melville"",
                                ""title"": ""Moby Dick"",
                                ""isbn"": ""0-553-21311-3"",
                                ""price"": 8.99
                          },
                          { ""category"": ""fiction"",
                                ""author"": ""J. R. R. Tolkien"",
                                ""title"": ""The Lord of the Rings"",
                                ""isbn"": ""0-395-19395-8"",
                                ""price"": 22.99
                          }
                        ],
                        ""bicycle"": {
                          ""color"": ""red"",
                          ""price"": 19.95
                        }
                  }
                }
            ";
            var json = JObject.Parse(input);
            var context = new JsonPathContext { ValueSystem = new JsonNetValueSystem() };
            var values = context.SelectNodes(json, "$.store.book[*].author").Select(node => node.Value);
            Console.WriteLine(JsonConvert.SerializeObject(values));
            Console.ReadKey();
        }
    }
    

    which produces this output:

    ["Nigel Rees","Evelyn Waugh","Herman Melville","J. R. R. Tolkien"]
    

    This example is based on the Javascript sample at the JsonPath site:

    • Javascript Usage and Example
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
Basically, what I'm trying to create is a page of div tags, each has
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

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.