Comments (5)
The placeholder #
without a number is a hack and it works only for the wildcard parts so you have to add the c manually:
` builder := jsonpath.PlaceholderExtension()
path, err := builder.NewEvaluable(`{#: $..c}`)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
v := interface{}(nil)
err = json.Unmarshal([]byte(`{ "a": { "b": { "c": 1, "d": 2 } } }`), &v)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
devices, err := path(context.Background(), v)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
for device, name := range devices.(map[string]interface{}) {
fmt.Printf("%s -> %v\n", device, name)
}
// Unordered output:
// $["a"]["b"] -> 1`
Actually palceholders should be used like #0
or #1
to access the nth key or in case of ..
an array of the keys. (see the gval example in godoc)
from jsonpath.
Hi moshevi,
in this package is an extension for placeholders. This isn't official json path anymore but it helps to access the keys.
The path {#: $..x}
will return a map[string]interface{} from jsonpath to value. In this case $["a"]["b"]["c"]
from jsonpath.
Hi @generikvault
Can you send me a code sample for that?
Thanks.
from jsonpath.
Thanks @generikvault
from jsonpath.
@generikvault Is there any samples for using regex for jsonpath or gval?
from jsonpath.
Related Issues (20)
- can't deal some strings with numbers and special chars!!!!! HOT 3
- Incorrect return value when querying for array HOT 8
- 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.