在Python中通过jq从API过滤JSON [英] Filtering JSON from API through jq in Python

查看:126
本文介绍了在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)) TypeError:模块"对象不可调用

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.

这篇关于在Python中通过jq从API过滤JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆