Low code JSON to extract data in one line

Overview

JSON Inline

Low code JSON to extract data in one line

Codecov Codecov Build Status Versions Release

ENG

RU

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:

>> "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"} ">
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:

>> {"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" ">
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

ENG

Установка

pip install json-inline

Правила использования

Модификатор Описание
?key:value Поиск первого вхождения объекта в массиве с нужным ключем и значением
?key Поиск первого вхождения объекта в массиве с нужным ключем
?+key Поиск первого вхождения объекта в массиве с нужным ключем и возврат данных по ключу
?key#num Поиск объекта в массиве с нужным ключем и указанием номера вхождения (по умолчанию #1)
?+key#num Поиск объекта в массиве с нужным ключем, указанием номера вхождения и возврат данных по ключу
.key Переход на новый уровень вложенности по ключу
.#index Переход на новый уровень вложенности по индексу массива

Примеры использования

Поиск в массиве по ключу и значению:

>> "false" # Поиск первого вхождения объекта в массиве с ключем vegetable и значением tomato json_inline.fetch(test_struct, '?vegetable:tomato') # >>> {"vegetable": "tomato", "yummy": "false"} ">
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"}

Поиск в массиве по ключу:

>> {"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 = [
    {
        "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"
You might also like...
Editor for json/standard python data
Editor for json/standard python data

Editor for json/standard python data

Convert your JSON data to a valid Python object to allow accessing keys with the member access operator(.)

JSONObjectMapper Allows you to transform JSON data into an object whose members can be queried using the member access operator. Unlike json.dumps in

This open source Python project allow you to create JSON data trees using Minmup.com
This open source Python project allow you to create JSON data trees using Minmup.com

This open source Python project allow you to create JSON data trees using Minmup.com. I try to develop this project all the time. But feel free to use :).

A python library to convert arbitrary strings representing business opening hours into a JSON format that's easier to use in code

A python library to convert arbitrary strings representing business opening hours into a JSON format that's easier to use in code

Generate code from JSON schema files

json-schema-codegen Generate code from JSON schema files. Table of contents Introduction Currently supported languages Requirements Installation Usage

JSON Interoperability Vulnerability Labs
JSON Interoperability Vulnerability Labs

JSON Interoperability Vulnerability Labs Description These are the companion labs to my research article "An Exploration of JSON Interoperability Vuln

A tools to find the path of a specific key in deep nested JSON.
A tools to find the path of a specific key in deep nested JSON.

如何快速从深层嵌套 JSON 中找到特定的 Key #公众号 在爬虫开发的过程中,我们经常遇到一些 Ajax 加载的接口会返回 JSON 数据。

cysimdjson - Very fast Python JSON parsing library

Fast JSON parsing library for Python, 7-12 times faster than standard Python JSON parser.

simplejson is a simple, fast, extensible JSON encoder/decoder for Python

simplejson simplejson is a simple, fast, complete, correct and extensible JSON http://json.org encoder and decoder for Python 3.3+ with legacy suppo

Releases(v0.1.3)
Owner
Aleksandr Sokolov
Aleksandr Sokolov
A query expression for extracting data from JSON.

JSONPATH A selector expression for extracting data from JSON. Quickstarts Installation Install the stable version from PYPI. pip install jsonpath-extr

林玮 (Jade Lin) 33 Oct 22, 2022
Fileson - JSON File database tools

Fileson is a set of Python scripts to create JSON file databases

Joonas Pihlajamaa 2 Feb 02, 2022
Random JSON Key:Pair Json Generator

Random JSON Key:Value Pair Generator This simple script take an engish dictionary of words and and makes random key value pairs. The dictionary has ap

Chris Edwards 1 Oct 14, 2021
RedisJSON - a JSON data type for Redis

RedisJSON is a Redis module that implements ECMA-404 The JSON Data Interchange Standard as a native data type. It allows storing, updating and fetching JSON values from Redis keys (documents).

3.4k Dec 29, 2022
Convert Wii UI formats to JSON5 and vice versa

Convert Wii UI formats to JSON5 and vice versa

Pablo Stebler 11 Aug 28, 2022
cysimdjson - Very fast Python JSON parsing library

Fast JSON parsing library for Python, 7-12 times faster than standard Python JSON parser.

TeskaLabs 235 Dec 29, 2022
A fast JSON parser/generator for C++ with both SAX/DOM style API

A fast JSON parser/generator for C++ with both SAX/DOM style API Tencent is pleased to support the open source community by making RapidJSON available

Tencent 12.6k Dec 30, 2022
Low code JSON to extract data in one line

JSON Inline Low code JSON to extract data in one line ENG RU Installation pip install json-inline Usage Rules Modificator Description ?key:value Searc

Aleksandr Sokolov 12 Mar 09, 2022
Json GUI for No Man's Sky save file

NMS-Save-Parser Json GUI for No Man's Sky save file GUI python NMS_SAVE_PARSER.py [optional|save.hg] converter only python convert.py usage: conver

2 Oct 19, 2022
JSON for Modern C++ Release Scripts

JSON for Modern C++ Release Scripts Preparations Install required tools: make install_requirements. Add required keys to config.json (apparently not c

Niels Lohmann 4 Sep 19, 2022
JSON Schema validation library

jsonschema A JSON Schema validator implementation. It compiles schema into a validation tree to have validation as fast as possible. Supported drafts:

Dmitry Dygalo 309 Jan 01, 2023
A Cobalt Strike Scanner that retrieves detected Team Server beacons into a JSON object

melting-cobalt 👀 A tool to hunt/mine for Cobalt Strike beacons and "reduce" their beacon configuration for later indexing. Hunts can either be expans

Splunk GitHub 150 Nov 23, 2022
Small python wrapper around the valico rust library to provide fast JSON schema validation.

Small python wrapper around the valico rust library to provide fast JSON schema validation.

Simon J Knibbs 5 Jul 12, 2019
JSONx - Easy JSON wrapper packed with features.

🈷️ JSONx Easy JSON wrapper packed with features. This was made for small discord bots, for big bots you should not use this JSON wrapper. 📥 Usage Cl

2 Dec 25, 2022
A Python application to transfer Zeek ASCII (not JSON) logs to Elastic/OpenSearch.

zeek2es.py This Python application translates Zeek's ASCII TSV logs into ElasticSearch's bulk load JSON format. For JSON logs, see Elastic's File Beat

Corelight, Inc. 28 Dec 22, 2022
Roamtologseq - A script loads a json export of a Roam graph and cleans it up for import into Logseq

Roam to Logseq The script loads a json export of a Roam graph and cleans it up f

Sebastian Pech 4 Mar 07, 2022
Simple Python Library to convert JSON to XML

json2xml Simple Python Library to convert JSON to XML

Vinit Kumar 79 Nov 11, 2022
simdjson : Parsing gigabytes of JSON per second

JSON is everywhere on the Internet. Servers spend a *lot* of time parsing it. We need a fresh approach. The simdjson library uses commonly available SIMD instructions and microparallel algorithms to

16.3k Dec 29, 2022
import json files directly in your python scripts

Install Install from git repository pip install git+https://github.com/zaghaghi/direct-json-import.git Use With the following json in a file named inf

Hamed Zaghaghi 51 Dec 01, 2021
A Python tool that parses JSON documents using JsonPath

A Python tool that parses JSON documents using JsonPath

8 Dec 18, 2022