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%的行覆盖率
Metadata
Release files for eqjson 1.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| eqjson-1.0.1.tar.gz | 5.8 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| eqjson-1.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 13.0 kB
Release files / eqjson-1.0.1.tar.gz
| Download URL | eqjson-1.0.1.tar.gz |
|---|---|
| Size | 5.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6a08fdeac919ab73b5806fc1a51d0edda4eebad2df81b6112cc24c4af3f70748
|
|
BLAKE2b-256 checksum How to use checksums |
21df0dd7903e2dcef5aa1ad53064812643b598b7e11abd5bcd8fc4e7ad96e769
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / eqjson-1.0.1-py3-none-any.whl
| Download URL | eqjson-1.0.1-py3-none-any.whl |
|---|---|
| Size | 7.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b328b00ca952cceae4d8215ab87eab78b66fd70dd6979a74780465b444c69748
|
|
BLAKE2b-256 checksum How to use checksums |
0a76b67d402bbadf2a2315ec233322ce0aca09cbe91a5ce4996a30fe4fb1630e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for eqjson 1.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.