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.7.tar.gz
(2.1 kB
view hashes)
Built Distribution
Close
Hashes for jsonpath_kv-0.0.7-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3afb2263188b04b62eb811f9a99e21930d600a51e8c4980bbfff9f9fe5fc3de8 |
|
MD5 | d04905188612b50d5fc13794662ad103 |
|
BLAKE2b-256 | 47001a1fc109b78262b2241d3a774ee279d34b5dd1667c020c3685ab55d5f51f |