-
Notifications
You must be signed in to change notification settings - Fork 0
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
query for first nesting level #4
Comments
@Chutchev what do you mean exactly by |
this is a single object. |
Ok, then in order to use the query capabilities you have to convert this to a list/array and query for the first object with status=="published". To create a list of the whole current JSON you can use the So putting all together that would be:
If the status is published it will return the whole object. Let me know if that's what you needed. |
Wow, thank you. It works |
Okay, does this mean that if I want to use a filter on the first level, I must always wrap the root in a list?
|
It's not the level, but the fact that queries works only on lists, see https://github.com/tidwall/gjson/blob/master/SYNTAX.md#queries If you have already a list of objects you don't need the [
{
"id": "uuid4_1",
"vendor": {
"id": "vendor_uuid4",
"name": "vendor_name",
"slug": "vendor_slug"
},
"vendor_id": "vendor_uuid4",
"name": "course_name",
"slug": "course_slug",
"status": "published"
},
{
"id": "uuid4_2",
"vendor": {
"id": "vendor_uuid4",
"name": "vendor_name",
"slug": "vendor_slug"
},
"vendor_id": "vendor_uuid4",
"name": "course_name",
"slug": "course_slug",
"status": "archived"
}
] You can query the first object with a given status with:
or all the objects with a given status with:
|
Hi, @volans-
I have json like this:
status can have values such as: published, archived. I want to check that this course have status equals published, but I can't create query to status field. I didn't find similar examples In original library documentations. How can I do it?
The text was updated successfully, but these errors were encountered: