【发布时间】:2021-11-13 16:27:39
【问题描述】:
抱歉,我尝试过但无法让我的 JMESPath 过滤工作来过滤 Github GraphQL 以获取私有存储库。
这是我要过滤的 Github GraphQL 结果:
{
"data": {
"repositoryOwner": {
"repositories": {
"edges": [
{
"node": {
"name": "foo",
"isFork": false,
"isPrivate": true,
"createdAt": "2019-04-25T20:31:07Z",
"updatedAt": "2019-04-30T03:44:30Z",
"primaryLanguage": {
"primaryLanguage": "JavaScript"
}
}
},
{
"node": {
"name": "bar",
"isFork": false,
"isPrivate": true,
"createdAt": "2019-04-25T01:26:31Z",
"updatedAt": "2019-04-28T23:16:03Z",
"primaryLanguage": {
"primaryLanguage": "JavaScript"
}
}
},
{
"node": {
"name": "fur",
"isFork": false,
"isPrivate": false,
"createdAt": "2019-04-25T02:46:28Z",
"updatedAt": "2019-06-12T15:46:30Z",
"primaryLanguage": {
"primaryLanguage": "JavaScript"
}
}
},
{
"node": {
"name": "blog",
"isFork": false,
"isPrivate": false,
"createdAt": "2013-03-17T13:37:44Z",
"updatedAt": "2019-06-08T02:58:44Z",
"primaryLanguage": null
}
},
{
"node": {
"name": "blogs",
"isFork": false,
"isPrivate": true,
"createdAt": "2015-12-06T03:52:14Z",
"updatedAt": "2016-02-27T05:17:52Z",
"primaryLanguage": {
"primaryLanguage": "CSS"
}
}
}
]
}
}
}
}
我试过了
data.repositoryOwner.repositories.edges.node[?isPrivate==`true`]
data.repositoryOwner.repositories.edges[].node[?isPrivate==`true`]
data.repositoryOwner.repositories.edges[].[node[?isPrivate==`true`]]
但是他们都没有给我我想要的列表,因为https://jmespath.org/tutorial.html 中的每个示例都是关于过滤数组元素,而我上面的不是。
类似的情况,对于
curl -s https://api.github.com/repos/golang/go/events | jp "[?type=='IssuesEvent'].payload.{Title: issue.title, URL: issue.url, User: issue.user.login, Event: action}"
如何在payload.action=='created'上面进一步过滤(不使用管道的地方)?
更新2:
答案是,
[?type=='IssueCommentEvent' && payload.action=='created'].payload.{Title: issue.title, URL: issue.url, User: issue.user.login, Event: action}
我们会得到:
[
{
"Title": "x/website: post https://go.dev/blog/tidy-web contains a broken link",
"URL": "https://api.github.com/repos/golang/go/issues/47975",
"User": "ilikegolang",
"Event": "created"
},
{
"Title": "cmd/compile: pointer to concrete type doesn't satisfy generic type method set",
"URL": "https://api.github.com/repos/golang/go/issues/48512",
"User": "DmitriyMV",
"Event": "created"
},
{
"Title": "How to solve this problem, run gomobile bind-target = android to report an error ",
"URL": "https://api.github.com/repos/golang/go/issues/48510",
"User": "ytxyyt",
"Event": "created"
},
. . .
]
请帮忙。
更新:
我问,“https://jmespath.org/tutorial.html 中的每个示例都是关于过滤数组元素,而我上面的不是”,然后得到:
为了过滤,你需要一个数组。
但是,这不是我所期望的,因为使用第一个作为示例,我期望过滤后是 JSON 数组:
[
{
"name": "foo",
"isFork": false,
"isPrivate": true,
"createdAt": "2019-04-25T20:31:07Z",
"updatedAt": "2019-04-30T03:44:30Z",
"primaryLanguage": {
"primaryLanguage": "JavaScript"
},
{
"name": "bar",
"isFork": false,
"isPrivate": true,
"createdAt": "2019-04-25T01:26:31Z",
"updatedAt": "2019-04-28T23:16:03Z",
"primaryLanguage": {
"primaryLanguage": "JavaScript"
},
{
"name": "blogs",
"isFork": false,
"isPrivate": true,
"createdAt": "2015-12-06T03:52:14Z",
"updatedAt": "2016-02-27T05:17:52Z",
"primaryLanguage": {
"primaryLanguage": "CSS"
}
]
我可以接受“不可能”作为答案,但这似乎是一个严重的设计缺陷,因为 JsonPath 可以轻松做到这一点。
【问题讨论】:
-
“为了过滤,你需要一个数组”,我知道根本原因可能是相似的@β.εηοιτ.βε,但我的要求与此不同回答。我在OP中说得更清楚了。所以我的问题的答案似乎是“否”?
-
哦,没有预期的结果就不清楚了。现在有点清楚了。不,您在这里所期望的完全可行,因为您“只是”想过滤
edges数组。如果到那时你还没有答案,我会在今天晚些时候试一试。
标签: json github graphql filtering jmespath