Code Monkey home page Code Monkey logo

Comments (8)

generikvault avatar generikvault commented on June 26, 2024

If the path points to a unique entry (it doesn't contain *, .. etc) it returns directly the requested value. This was done in order to support expressions like $.a + $.b

from jsonpath.

whitlockjc avatar whitlockjc commented on June 26, 2024

I have to agree with @BorisKozo, this causes a consistency issue. I'll look through the code to see if I can find the things that indicate it's a unique entry and update code to turn []any into [][]any. If I find something and write the code, I'll share it here.

from jsonpath.

whitlockjc avatar whitlockjc commented on June 26, 2024

@generikvault Would you be willing to help me come up with a way to parse/process a JSONPath string and tell when PaesslerAG/jsonpath has removed an outer slice? I'll do my best to do so but if you're willing, it could help us all out.

from jsonpath.

whitlockjc avatar whitlockjc commented on June 26, 2024

The quick and dirty is as simple as the following, but I'm worried it might not be this simple:

func wrapSingleValue(path string, value []any) []any {
    if !strings.Contains(path, "..") && !strings.Contains(path, "*") {
        return []any{value}
    }

    return value
}

If anyone can shed light on this, I'd appreciate it.

from jsonpath.

generikvault avatar generikvault commented on June 26, 2024

@whitlockjc this happens in path.go. when the path interface has the dynamic type plainPath a scalar value is returned otherwise the dynamic type is ambiguousPath and a slice is returned.

You can not really distinguish these two without parsing the path since paths like $["a", "b"] are also ambiguous.

It is probably the easiest to add a gval.ConsistantReturnLanguage.

from jsonpath.

whitlockjc avatar whitlockjc commented on June 26, 2024

But is $["a", "b"] valid JSONPath? I do not think that it is, no other JSONPath implementations seem to support it. If not, then the use cases above that support the need to deviate from the JSONPath "standard (quoted since it's not really a standard)" do not need to be supported for my tool and the naive approach above where you check the path for .., *, ? might be a decent approach. To test, I used multiple other JSONPath implementations to verify and it seems to work.

from jsonpath.

whitlockjc avatar whitlockjc commented on June 26, 2024

By the way, I appreciate you taking the time to explain/help.

from jsonpath.

generikvault avatar generikvault commented on June 26, 2024

For arrays it is valid: $.aList[1,4,9]

For objects I've seen different implementation.

Arrays hav also a range notation $.aList[0:3]

from jsonpath.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.