-
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
the return result has key absent problem #321
Comments
@Storm-Born as mentioned recently in #295 (comment) you can get a default value in arrays with the
to get: [["wangyiyi",20,null,"china"],["lisi",33,null,"england"],["luosan",40,null,"iceland"]] That said I think that relying on position in arrays for data it's usually brittle, hash keys are safer to be sure you're getting the right data. |
thank you.it works right. and I agree with your opinion but I don't see the hash keys syntax in the guidline, how should I write the path express to get the result format like below.
|
@Storm-Born I would just query for If you really want to get that output you can use:
Explanation: for each person object create a multipaths array with an object with the literal null value for That gives you: [{"sex":null,"name":"wangyiyi","age":20,"address":"china"},{"sex":null,"name":"lisi","age":33,"address":"england"},{"sex":null,"name":"luosan","age":40,"address":"iceland"}] but if any of the items has a vaue for the Maybe tidwall knows a better way to achieve this though. |
{
"persons": [
{
"name":"wangyiyi",
"age": 20,
"address":"china"
},
{
"name":"lisi",
"age": 33,
"address":"england"
},
{
"name":"luosan",
"age": 40,
"address":"iceland"
}
]
}
json data is above. I used the jsonpath "persons.#.[name,age,sex,address]", as you see, a give a key not exists. then gjson eat this key and just give me a result like blew:
[["wangyiyi",20,"china"],["lisi",33,"england"],["luosan",40,"iceland"]]
this behavior cause a problem that I don't know which key has no value and I can't map the existed value to it's key rightly.
The text was updated successfully, but these errors were encountered: