在 Python 中通过 jq 从 API 过滤 JSON [英] Filtering JSON from API through jq in Python
本文介绍了在 Python 中通过 jq 从 API 过滤 JSON的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试过滤掉字段名称"以存储在文件中.我是这样过滤的:
I'm trying to filter out the field "name" to store in a file. I'm filtering like so:
r =requests.get('https://api.spotify.com/v1/albums/70yMNdgyIj9SrQXFmdJKx9',
headers=headers)
print(jq(".[name]").transform(json.loads(r)))
我收到错误消息:print(jq(".[name]").transform(text=r))类型错误:模块"对象不可调用
I get the error: print(jq(".[name]").transform(text=r)) TypeError: 'module' object is not callable
对此事有帮助吗?jq python 绑定的文档对我来说不是很清楚 https://pypi.org/project/jq/
Any help on the matter? The documentation for jq python bindings is not very clear to me https://pypi.org/project/jq/
推荐答案
如异常消息所述,您正在尝试调用模块.
As the exception message states, you are trying to call a module.
您可能使用了 import jq
而不是 from jq import jq
.
You have probably used import jq
instead of from jq import jq
.
这篇关于在 Python 中通过 jq 从 API 过滤 JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文