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
The ldap2json script allows you to extract the whole LDAP content of a Windows domain into a JSON file.

ldap2json The ldap2json script allows you to extract the whole LDAP content of a Windows domain into a JSON file. Features Authenticate with password

Podalirius 68 Dec 7, 2022
Creates fake JSON files from a JSON schema

Use jsf along with fake data generators to provide consistent and meaningful fake data for your system.

Andy Challis 86 Jan 3, 2023
Json utils is a python module that you can use when working with json files.

Json-utils Json utils is a python module that you can use when working with json files. it comes packed with a lot of featrues Features Converting jso

Advik 4 Apr 24, 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
With the help of json txt you can use your txt file as a json file in a very simple way

json txt With the help of json txt you can use your txt file as a json file in a very simple way Dependencies re filemod pip install filemod Installat

Kshitij 1 Dec 14, 2022
Same as json.dumps or json.loads, feapson support feapson.dumps and feapson.loads

Same as json.dumps or json.loads, feapson support feapson.dumps and feapson.loads

boris 5 Dec 1, 2021
Ibmi-json-beautify - Beautify json string with python

Ibmi-json-beautify - Beautify json string with python

Jefferson Vaughn 3 Feb 2, 2022
jq for Python programmers Process JSON and HTML on the command-line with familiar syntax.

jq for Python programmers Process JSON and HTML on the command-line with familiar syntax.

Denis Volk 3 Jan 9, 2022
Simple, minimal conversion of Bus Open Data Service SIRI-VM data to JSON

Simple, minimal conversion of Bus Open Data Service SIRI-VM data to JSON

Andy Middleton 0 Jan 22, 2022
An tiny CLI to load data from a JSON File during development.

JSON Server - An tiny CLI to load data from a JSON File during development.

Yuvraj.M 4 Mar 22, 2022