Comments (9)
@volans- Or I want to get 123, is there any better way?
It depends on your data and what you want, for example you can get all the values for the key q!qq
with:
!stringMember|@fromstr|#.q!qq
that returns in this case:
[123]
If you know that you always want the first one then you can get it with:
!stringMember|@fromstr|#.q!qq|0
from gjson.
@15083787153 your message has some formatting problem, so I might have misunderstood, but it's probably just a problem of escaping the special character, see also the related doc.
With a JSON of:
{"!stringMember": "[{\"q!qq\": 123},{\"key2\": 2324}]"}
and a query of:
!stringMember|@fromstr|#(q\!qq).q!qq
you get: 123
Is that what yo were looking for?
from gjson.
this is my code:
`package main
import (
"fmt"
"github.com/tidwall/gjson"
)
func main() {
const jsonNew = {"!stringMember": "[{\"q!qq\": 123},{\"key2\": 2324}]"}
fmt.Println("result:", gjson.Get(jsonNew, !stringMember|@fromstr|#(q!qq).q!qq
))
}
`
but the result is empty
from gjson.
thank you so much! can you tell me all the special character?I need special handling for these special character,but I can't find it in the docs。
from gjson.
For that you have to ask @tidwall, I don't think all of them are documented and they might depend on where you use them. For example !
is used for literals in the syntax but does't need to be escaped in the path !stringMember
but it does in the query #(q\!qq)
.
That said, if you escape it in all places it works the same:
\!stringMember|@fromstr|#(q\!qq).q\!qq
from gjson.
@tidwall Do you know the range of special character? I need to do special processing in a specific area.
from gjson.
@volans- Or I want to get 123, is there any better way?
from gjson.
Through the documentation of gjson and my own practice, I found that these are special characters, but I don't know if there are more characters。
! ? * > < = \ % ( )
from gjson.
@volans- Or I want to get 123, is there any better way?
It depends on your data and what you want, for example you can get all the values for the key
q!qq
with:!stringMember|@fromstr|#.q!qq
that returns in this case:
[123]
If you know that you always want the first one then you can get it with:
!stringMember|@fromstr|#.q!qq|0
Thank you very much! This is exactly what I need.
from gjson.
Related Issues (20)
- Support empty paths HOT 2
- import "github.com/tidwall/gjson" is a program, not an importable package HOT 2
- Query for node that doesn't have specified field HOT 1
- Iterating only first N items in an array HOT 2
- Tilde operator treats values other than true and 1 as false HOT 3
- pretty modifiers are not working as expected HOT 2
- I need a set function to modify json string HOT 1
- What is the difference between raw and str HOT 1
- Querying nested optional array HOT 2
- Same problem as #259
- Accessing key with periods in it HOT 6
- How to use gjson's capabilities to convert json strings into objects HOT 1
- Flatten/Expand Array HOT 2
- join flat array to comma separated string HOT 2
- help with a query to get all paths in a nested json HOT 2
- forEach fo current json string HOT 4
- How to get next value under ForEach function HOT 2
- How to pick up specific values from array of objects into target array of objects? HOT 2
- How to apply multipaths to all elements of an array HOT 1
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 gjson.