Gets the value in the JSON data
Project description
jsonpath-kv
pip install jsonpath-kv
from jsonpath_kv import jsonvalue
正常的dict
user_dict = {
"sites":
[
{ "name":"runoob" , "url":"www.runoob.com" },
{ "name":"google" , "url":"www.google.com" },
{ "name":"weibo" , "url":"www.weibo.com" }
]
}
r = jsonvalue.get(user_dict,'url')
print(r)
output: ['www.runoob.com', 'www.google.com', 'www.weibo.com']
json字符串
user_json = '{ "sites": [ { "name":"runoob" , "url":"www.runoob.com" }, { "name":"google" , "url":"www.google.com" }, { "name":"weibo" , "url":"www.weibo.com" } ] }'
r = jsonvalue.get(user_dict,'url')
print(r)
output: ['runoob', 'google', 'weibo']
当所取key在字符串包裹里时
user_json = { "sites": '[ { "name":"runoob" , "url":"www.runoob.com" }, { "name":"google" , "url":"www.google.com" }, { "name":"weibo" , "url":"www.weibo.com" } ]'}
r = jsonvalue.get(user_dict,'url')
print(r)
output: ['runoob', 'google', 'weibo']
当所取key在字符串包裹里时
user_dict = {"sites": "{ \"name\":\"google\" , \"url\":\"www.google.com\" }"}
r = jsonvalue.get(user_dict,'name')
print(r)
output: ['google']
key不存在时返回false
user_dict = {"sites": "{ \"name\":\"google\" , \"url\":\"www.google.com\" }"}
r = jsonvalue.get(user_dict, 'address')
print(r)
output: False
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
jsonpath-kv-0.0.8.tar.gz
(2.1 kB
view details)
File details
Details for the file jsonpath-kv-0.0.8.tar.gz
.
File metadata
- Download URL: jsonpath-kv-0.0.8.tar.gz
- Upload date:
- Size: 2.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.6.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0a6ccbb67998bd4f876f7ce13de9c7104c933213a3171289d1489828293e3425 |
|
MD5 | 55fe8d57bbf6930954870ce7aee67682 |
|
BLAKE2b-256 | 55296040385cb051405687549c8d456b405628610eee7458870d06d5f46eae30 |