json提取器
Project description
我们在提取json串中的某个值得时候难免会碰到一层一层又一层的嵌套 想要提取要一层一层的找key 像剥洋葱一样 今天安利一款暴力提取库 json_extract
极速上手教程
安装 json_extract
pip install json-extract
{
"animals": {
"zoon": [
{
"name": "Peki",
"sex": "girl",
"age": 18
},
{
"name": "George",
"sex": "boy",
"type":"zoon"
}
],
"people": [
{
"name": "Rufus",
"sex": "girl",
"weight":"88"
},
{
"name": "Marty",
"sex": "boy",
"people": [
{
"name": "Rufus",
"type":"people",
},
{
"name": "Marty",
"sex": "???",
"age": "10"
}]
}]
}
}
response_json={}
from json_extract import GetValue2
getobj = GetValue2(response_json)
sex = getobj.get_values('sex')
print(sex)
# ['girl', 'boy', 'girl', 'boy']
deep = getobj.get_values("sex",deep=True)
# ['girl', 'boy', 'girl', 'boy', '???']
filte = getobj.get_values("sex",filters=True)
# ['girl', 'boy']
notexiste = getobj.get_values("asdfadfs",default='not existe')
# or
getobj.get_values("asdfadfs",'not existe')
# not existe
weight = getobj.get_values("weight")
# 88
weight_shell = getobj.get_values("weight",shell=True)
# ['88']
age = getobj.get_values("age")
# [18, '10']
age_int = getobj.get_values('age',ret_type=int)
# [18, 10]
age_str = getobj.get_values("age",ret_type=str)
# ['18', '10']
:param key: Key value to be resolved 需要解析的key值
:param default: If the result is empty, the default value is none 如果结果为空 备用值 默认None
:param deep: Do you want to deeply resolve all keys? Default false 是否深度解析所有key 默认False
:param filters: Whether to de duplicate the result, the default is false 是否去重结果 默认False
:param shell: If the result is whether to remove the outer list shell, the default is false 如果结果为一个 是否去掉外面list壳子 默认False(去壳)
:param ret_type: The return result type can pass in 'int' or 'str' by default 返回结果类型 可传入'int'或'str' 默认原始
End
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
json_extract-1.1.2.tar.gz
(3.0 kB
view details)
File details
Details for the file json_extract-1.1.2.tar.gz
.
File metadata
- Download URL: json_extract-1.1.2.tar.gz
- Upload date:
- Size: 3.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 12250fc135b0a4106fedcf44e58d472e8c6e62926b4ddc29cc7caf5c227c46d1 |
|
MD5 | 0e848d26df2e80f7e585559c6af54a12 |
|
BLAKE2b-256 | 97f1083e53002ffa6851d969e5338359079cb8be73a7b991231188c3b0a3b78c |