Skip to main content

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


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)

Uploaded Source

Built Distribution

jsonpath_kv-0.0.7-py3-none-any.whl (6.4 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page