JSON Inline
Low code JSON to extract data in one line
ENG
Installation
pip install json-inline
Usage Rules
| Modificator | Description |
|---|---|
?key:value |
Search first object's entry in array by key:value pair |
?key |
Search first object's entry in array by key |
?+key |
Search first object's entry in array by key and return data by key |
?key#num |
Search object in array by key with specify entry's count (default #1) |
?+key#num |
Search object in array by key with specify entry's count and return data by key |
.key |
Move forward in object by key |
.#index |
Move forward in array by index |
Usage
Search in array by key and value:
import json_inline
test_struct = [
{
"fruit": "apple",
"yummy": "true"
},
{
"vegetable": "tomato",
"yummy": "false"
},
{
"vegetable": "cucumber",
"yummy": "false"
}
]
# Search first object's entry in array with key vegetable and value cucumber,
# return value from yummy key
json_inline.fetch(test_struct, '?vegetable:cucumber.yummy')
# >>> "false"
# Search first object's entry in array with key vegetable and value tomato
json_inline.fetch(test_struct, '?vegetable:tomato')
# >>> {"vegetable": "tomato", "yummy": "false"}
Search in array by key:
import json_inline
test_struct = [
{
"animal": "cat"
},
{
"animal": "dog"
},
{
"plant": "tomato"
},
{
"thing": "book"
}
]
# Search first object's entry in array with key animal
json_inline.fetch(test_struct, '?animal')
# >>> {"animal": "cat"}
# Search second object's entry in array with key animal
json_inline.fetch(test_struct, '?animal#2')
# >>> {"animal": "dog"}
# Search second object's entry in array with key animal,
# return value from animal key
json_inline.fetch(test_struct, '?+animal#2')
# >>> "dog"
Nested navigation:
import json_inline
test_struct = [
{'item1': 'fail'},
{'item2': 'fail'},
{'item2': [
{'item4': 'fail'},
{'item4': 'fail'},
{'item5': [
{'item7': 'fail'},
{'item7': 'fail', 'item9': [
{'item10': 'fail'},
{'item10': 'fail'},
{'item10': 'fail'},
{'item10': 'fail'},
{'item10': 'success'},
]},
{'item8': 'fail'},
]},
{'item5': 'fail'},
{'item6': 'fail'},
]},
{'item3': 'fail'}
]
# Movement variant used array index to reach needs value
json_inline.fetch(test_struct, '?+item2#2.?+item5.?item7:fail#2.item9.#4.item10')
# Stable variant used search by array instead index move
json_inline.fetch(test_struct, '?+item2#2.?+item5.?item7:fail#2.item9.?item10:success.item10')
# >>> "success"
RU
Установка
pip install json-inline
Правила использования
| Модификатор | Описание |
|---|---|
?key:value |
Поиск первого вхождения объекта в массиве с нужным ключем и значением |
?key |
Поиск первого вхождения объекта в массиве с нужным ключем |
?+key |
Поиск первого вхождения объекта в массиве с нужным ключем и возврат данных по ключу |
?key#num |
Поиск объекта в массиве с нужным ключем и указанием номера вхождения (по умолчанию #1) |
?+key#num |
Поиск объекта в массиве с нужным ключем, указанием номера вхождения и возврат данных по ключу |
.key |
Переход на новый уровень вложенности по ключу |
.#index |
Переход на новый уровень вложенности по индексу массива |
Примеры использования
Поиск в массиве по ключу и значению:
import json_inline
test_struct = [
{
"fruit": "apple",
"yummy": "true"
},
{
"vegetable": "tomato",
"yummy": "false"
},
{
"vegetable": "cucumber",
"yummy": "false"
}
]
# Поиск первого вхождения объекта в массиве с ключем vegetable и значением cucumber,
# возврат значения yummy из найденной структуры
json_inline.fetch(test_struct, '?vegetable:cucumber.yummy')
# >>> "false"
# Поиск первого вхождения объекта в массиве с ключем vegetable и значением tomato
json_inline.fetch(test_struct, '?vegetable:tomato')
# >>> {"vegetable": "tomato", "yummy": "false"}
Поиск в массиве по ключу:
import json_inline
test_struct = [
{
"animal": "cat"
},
{
"animal": "dog"
},
{
"plant": "tomato"
},
{
"thing": "book"
}
]
# Поиск первого вхождения объекта в массиве с ключем animal
json_inline.fetch(test_struct, '?animal')
# >>> {"animal": "cat"}
# Поиск второго вхождения объекта в массиве с ключем animal
json_inline.fetch(test_struct, '?animal#2')
# >>> {"animal": "dog"}
# Поиск второго вхождения объекта в массиве с ключем animal,
# возврат значения из найденного ключа (animal)
json_inline.fetch(test_struct, '?+animal#2')
# >>> "dog"
Навигация по структурам:
import json_inline
test_struct = [
{'item1': 'fail'},
{'item2': 'fail'},
{'item2': [
{'item4': 'fail'},
{'item4': 'fail'},
{'item5': [
{'item7': 'fail'},
{'item7': 'fail', 'item9': [
{'item10': 'fail'},
{'item10': 'fail'},
{'item10': 'fail'},
{'item10': 'fail'},
{'item10': 'success'},
]},
{'item8': 'fail'},
]},
{'item5': 'fail'},
{'item6': 'fail'},
]},
{'item3': 'fail'}
]
# Вариант с движением по массиву через индекс
json_inline.fetch(test_struct, '?+item2#2.?+item5.?item7:fail#2.item9.#4.item10')
# Более надежный вариант с поиском значения путем перебора
json_inline.fetch(test_struct, '?+item2#2.?+item5.?item7:fail#2.item9.?item10:success.item10')
# >>> "success"
Metadata
Release files for json-inline 0.1.8
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 | Actions |
|---|---|---|---|---|
| json_inline-0.1.8.tar.gz | 5.4 kB | Without provenance | Details for json_inline-0.1.8.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| json_inline-0.1.8-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details for json_inline-0.1.8-py2.py3-none-any.whl |
Total release size: 10.9 kB
Release files / json_inline-0.1.8.tar.gz
| Download URL | json_inline-0.1.8.tar.gz |
|---|---|
| Size | 5.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
90369e3508aa00be1a9c371c2c9ac09c8b40d01b1e5d9d8ad2806dfd2dffc2ed
|
|
BLAKE2b-256 checksum How to use checksums |
b9cf7088311fe3ab258482a436ae8296befeddf50ea2acf248bfb5b757216aec
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.2 importlib_metadata/4.6.4 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.1 CPython/3.9.2
|
Release files / json_inline-0.1.8-py2.py3-none-any.whl
| Download URL | json_inline-0.1.8-py2.py3-none-any.whl |
|---|---|
| Size | 5.5 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
684d50caf13d213f4b7a30cce8e4309936309003c04023cc6cef2a836910bc85
|
|
BLAKE2b-256 checksum How to use checksums |
4bd6523c3da9f7f28bb680f376b32a79f48437b9ee5ad84cf31636a0e36ba17c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.2 importlib_metadata/4.6.4 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.1 CPython/3.9.2
|
Security for json-inline 0.1.8
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.