Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add usage example read-me document #4

Open
NigelThorne opened this issue Sep 14, 2018 · 3 comments
Open

Add usage example read-me document #4

NigelThorne opened this issue Sep 14, 2018 · 3 comments

Comments

@NigelThorne
Copy link
Contributor

I took a look at your code... I was trying to swap to your library from the Newtonsoft JSONPath implementation...

I can't work out how to do that.

How do I use your code? please can you update the readme with a worked example.. :)

Thanks,
Nigel

@atifaziz atifaziz changed the title Readme... Add usage example read-me document Sep 14, 2018
@atifaziz
Copy link
Owner

Meanwhile, have a look at the answer by Rick Sladkey to the question “How to use C# example using JsonPath?” on StackOverflow.

@NigelThorne
Copy link
Contributor Author

Thanks for that...
I'm still hitting problems running through your examples in your readme.
None of the expressions in [] seem to work (because the ScriptEvaluator is missing).

My goal is to get all the examples in your Readme working...

    class JsonPathExecutor
    {
        public JContainer Apply(string input, string path)
        {
            var source = JToken.Parse(input);
            return new JArray(ApplyObj(path, source));
        }

        private object[] ApplyObj(string path, JToken source)
        {
            var context = new JsonPathContext
            {
                ValueSystem = new JsonNetValueSystem(),
                ScriptEvaluator = EvaluateScript
            };

            return context.Select(source, path).ToArray();
        }

        private object EvaluateScript(string path, object obj, string arg3)
        {
            var p = Regex.Replace(path, "^@", "");
            var results = ApplyObj(p, obj as JToken);
            return results.Any() ? new JArray(results) : null;
        }

I'm currently doing this... but it's not working exactly...

https://bitbucket.org/nigel__thorne/jsonpathsandbox/branch/JSONPath-experiment

@cburgmer
Copy link

I can offer https://github.com/cburgmer/json-path-comparison/tree/master/implementations/dotNET_JsonPathLib

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants