Skip to main content

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.

Source Distribution

eqjson-1.0.1.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

eqjson-1.0.1-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

Details for the file eqjson-1.0.1.tar.gz.

File metadata

  • Download URL: eqjson-1.0.1.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for eqjson-1.0.1.tar.gz
Algorithm Hash digest
SHA256 6a08fdeac919ab73b5806fc1a51d0edda4eebad2df81b6112cc24c4af3f70748
MD5 d9aa1c20b2a3b32651d75b031236f82b
BLAKE2b-256 21df0dd7903e2dcef5aa1ad53064812643b598b7e11abd5bcd8fc4e7ad96e769

See more details on using hashes here.

File details

Details for the file eqjson-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for eqjson-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b328b00ca952cceae4d8215ab87eab78b66fd70dd6979a74780465b444c69748
MD5 4b3c0a8b7959f310e2aa7641ac8fcf48
BLAKE2b-256 0a76b67d402bbadf2a2315ec233322ce0aca09cbe91a5ce4996a30fe4fb1630e

See more details on using hashes here.

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