Skip to main content
Join the official 2019 Python Developers SurveyStart the survey!

An smart json,similar to the jquery, read and update the json data

Project description

ejson

An smart json,similar to the jquery, read and update the json data.

一个小巧的、完全无依赖的类似jquery写法的读取和更改json的工具,可以按照json的层级或者某个属性读取json数据。

Installing aelog

  • pip install eqjson

Usage

假如json数据如下:

[
   {
      'object':{
         'name':'myLittleObject',
         'value':[
            {
               'key2':'value2',
               'key3':'value3',
               'key1':'value1'
            },
            {
               'key33':'value33',
               'key1':'value11'
            },
            {
               'key333':'value333',
               'key1':'value111'
            }
         ],
         'type':'list',
         'valueAsString':[
            'one',
            'two'
         ]
      }
   }
]
from eqjson import EasyQueryjson

# 实例化
ejson_obj = EasyQueryjson(json_doc)
# 查询
ejson_obj.get_value("object.name")
ejson_obj.get_value("object.valueAsString.0")
# update
ejson_obj.change_value("object.name", "updatename")
ejson_obj.change_value("object.value.2", ["five", "four"])
# add
ejson_obj.append_value("object.valueAsString", "three")
ejson_obj.append_value("object.valueA", {"test":456})
# remove
ejson_obj.remove_value("object.valueAsString")
ejson_obj.remove_value("object.value")

# 具体的查询参数详情如下

基本用法:

  • 如果要获取name值:则写法为0.object.name
  • 如果json最外层是{}获取name值:则写法为object.name
  • 如果要获取valueAsString中的第一个值:则写法为0.object.valueAsString.0
  • 如果json最外层是{}获取valueAsString中的第一个值:则写法为object.valueAsString.0
  • 获取value列表中的第一个值的key1值:则写法为0.object.value.0.key1
  • 获取value列表中的所有的key1值:则写法为0.object.value.key1, 则结果为['value1','value11', 'value111']

高级用法:

  • 支持通过属性确定值,如果json是无序的,要获取key1值为value1所在节点的key3的值,则写法为0.object.value[key1=value1].key3
  • 支持通过多属性确定值,比如要获取key1值为value1,key2值为value2,所在节点的key3的值,则写法为0.object.value[key1=value1,key2=value2].key3
  • 支持多层属性,比如要获取name为myLittleObject的以上的值:则写法为[name=myLittleObject].object.value[key1=value1].key3

单测

  • 100%文件覆盖率,92%的行覆盖率

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for eqjson, version 1.0.1
Filename, size File type Python version Upload date Hashes
Filename, size eqjson-1.0.1-py3-none-any.whl (7.3 kB) File type Wheel Python version py3 Upload date Hashes View hashes
Filename, size eqjson-1.0.1.tar.gz (5.8 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page