-
Notifications
You must be signed in to change notification settings - Fork 860
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
can't get length of array if the path has a number as key ":4". #312
Comments
and seems like can't insert number item in empty array: |
The key in your JSON is just |
Thank you but I think query "Normally number keys are used to modify arrays, but it's possible to force a numeric object key by using the colon character:" Finally I find out |
@Databingo but that's sjson documentation though and I don't see the same note on the gjson documentation. You can test what I've mentioned earlier in https://gjson.dev/ The first |
@volans- Thanks a lot, I got it, why not author keep gjson same syntax ":4" with sjson in case someone use number as object key accidentally? Maybe package could figure out that's an object so Finally I think no need because user no need to consider which situation(array index or object key) it is when use a number in query. Still have another question: seems like sjson can't insert number item in an empty array: |
Sorry I'm not familiar with the |
@volans- Thank you! |
@Databingo For |
@tidwall Thanks a lot, I got it! |
suppose json is :
j := [0,1,2,3,{"4": {"test0":[1,2,3,"4"]}}]
run:
length := gjson.Get(j, "4.:4.test0.#").Int()
get 0;
but if change data key from number "4" to string "a":
j := [0,1,2,3,{"a": {"test0":[1,2,3,"4"]}}]
then run:
length := gjson.Get(j, "4.a.test0.#").Int()
get 4.
The different is the path where change :4 to a. Is this a problem or I miss something?
The text was updated successfully, but these errors were encountered: