Comments (8)
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.
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.
@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.
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.
@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.
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.
By the way, I appreciate you taking the time to explain/help.
from jsonpath.
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)
- can't deal some strings with numbers and special chars!!!!! HOT 3
- Error when using multiple array ranges
- Incorrect full path on search - bug HOT 1
- Results do not match other implementations
- Is it possible to find all nodes that have a certain key? HOT 3
- No error with incorrect path and missing field
- JSONPath comparison and standardisation
- error "mixed 63 and 44 in JSON bracket" is not helpful HOT 1
- Honor JSON annotations
- Single quotes are not supported HOT 1
- Support for [(@.length-1)]
- Support for `json.Number`
- undefined: jsonpath.PlaceholderExtension, how to fix it? HOT 1
- Question: How to update JSON at path HOT 1
- Option to allow for Single-Quoted strings HOT 2
- filter with a boolean value doesn't work
- Invalid/undefined keys error out in JSONPath, but not in GVal
- Consider implementing RFC 9535
- Update placeholder `#` hack to work better HOT 10
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jsonpath.