A library for dynamic search and retrieve data from JSON datasets
Project description
JsonGetter: A headache-free way for dynamic search & retrieve through large JSON datasets.
Installation
install using pip:
pip install jsongetter
Methods
JsonGetter provides two main static methods for searching through JSON data:
from jsongetter import JsonGetter
# Search for values based on a specific key name and value type.
type_results = JsonGetter.type_search(data, "key", "value_type")
# Search for values that are nearby a specified key name. This method retrieves objects based on the key name.
nearby_results = JsonGetter.nearby_search(data, "key", "value", ["key_1", "key_2"...])
# When search_general=True is set, the search is not limited to nearby values in the JSON structure.
# This allows for finding keys at any depth within the specified object.
nearby_results_deep = JsonGetter.nearby_search(data, "key", "value", ["key_1", "key_2"...], search_general=True)
Supported Types:
- object
- array
- string
- boolean
- integer
- float
- null
Usage
from jsongetter import JsonGetter
sample_data = {
"flights": [
{
"plane": "Boeing 737",
"depart": "New York",
"arrive": "Los Angeles",
"number": "FL001",
"time": "14:30",
"info": {
"passengers": 121,
"available_seats": {"A": [30, 35, 49, 66]}
},
},
{
"plane": "Airbus A320",
"depart": "Chicago",
"arrive": "Miami",
"number": "FL002",
"time": "10:15"
}
],
"date": "2023-05-01"
}
# Retrieve all unique departure cities from the sample data.
depart_cities = JsonGetter.type_search(sample_data, "depart", "string")
print(depart_cities) # Output: ["New York", "Chicago"]
# Get related flight information for a specific departure city.
nearby_info = JsonGetter.nearby_search(
sample_data, "depart", "New York", ["number", "time"]
)
print(nearby_info) # Output: [{"number": "FL001", "time": "14:30"}]
# Retrieve the date of the flights.
date = JsonGetter.type_search(sample_data, "date", "string")
print(date) # Output: ['2023-05-01']
# Count the total number of flights available in the sample data.
flights = JsonGetter.type_search(sample_data, "flights", "array")[0]
print(len(flights)) # Output: 2
# Get the number of passengers for the first flight.
passengers = JsonGetter.type_search(flights[0], "passengers", "integer")
print(passengers) # Output: [121]
# Retrieve the available seats for the first flight.
seats = JsonGetter.type_search(flights[0], "available_seats", "object")
print(seats[0]['A']) # Output: [30, 35, 49, 66]
# Use nearby_search to get seat information.
seat_info = JsonGetter.nearby_search(
flights[0], "available_seats", None, ["A"]
)
print(seat_info) # Output: [{"A": [30, 35, 49, 66]}]
# Get flight information related to a specific departure city.
nearby_info = JsonGetter.nearby_search(
sample_data, "depart", "New York", ["info"]
)
print(nearby_info) # Output: [{"info": {"passengers": 121, "available_seats": {"A": [30, 35, 49, 66]}}}]
# Perform a deep search to find available seats, even if they are nested within other objects.
deep_seats = JsonGetter.nearby_search(
sample_data, "depart", "New York", ["available_seats"], search_general=True
)
print(deep_seats) # Output: [{"available_seats": {"A": [30, 35, 49, 66]}}]
License
This project is licensed under the MIT License - see the LICENSE file for details.
LICENSE
MIT License
Copyright (c) [2024] [Taq01]
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file jsongetter-1.0.0.tar.gz.
File metadata
- Download URL: jsongetter-1.0.0.tar.gz
- Upload date:
- Size: 6.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9d877d425dd33bb2607cea1447110166427d4354bda6c9cf626a1d06ab882249
|
|
| MD5 |
da27defe6f611a90396725de0709b2e6
|
|
| BLAKE2b-256 |
f8d130348e3b55a1ca8ae8ac7765f2be02a3fb1fd204d524e1a65286be115235
|
File details
Details for the file jsongetter-1.0.0-py3-none-any.whl.
File metadata
- Download URL: jsongetter-1.0.0-py3-none-any.whl
- Upload date:
- Size: 6.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2141b751892ac76a5b8a5baabe182808ecdb9b1d3923bf9708e7f3d75a2a225b
|
|
| MD5 |
f9bb85ce099705a6f0cb4febec48fae9
|
|
| BLAKE2b-256 |
6e862bf88cab77f360f53ac76fabbdf7116574b089a3eeff079c6fd467d5f6f5
|