JavaScript QoL for JSON in python
Project description
JSJ
JavaScript QoL for JSON in python.
Motivation
Being familiar with Python and with JavaScript, there was something that I just couldn't get over with JavaScript that python just doesn't have, dot notation for json. This library seeks to solve python json issues in a variety of domains.
Basic Usage
from jsj import *
url = "https://api.weather.gov/points/39.7632,-101.6483"
data = fetch(url) \
.json() \
.get_data()
assert data.properties.timeZone == "America/Chicago"
Requesting and flattening JSON
JSJ can flatten JSON documents, just like the pandas.normalize_json() function.
from jsj import *
# Some sample data
data = JSON([
{
"id": 1,
"name": "Cole Volk",
"fitness": {"height": 130, "weight": 60},
},
{"name": "Mark Reg", "fitness": {"height": 130, "weight": 60}},
{
"id": 2,
"name": "Faye Raker",
"fitness": {"height": 130, "weight": 60},
},
])
data_flattened, keys = data.flatten()
assert data_flattened[0] == {
"id": 1,
"name": "Cole Volk",
"fitness_height": 130,
"fitness_weight": 60,
}
Getting the albums released by an artist
# Sets the URLs `artist` parameter to Post Malone
url = "https://musicbrainz.org/ws/2/release?artist=b1e26560-60e5-4236-bbdb-9aa5a8d5ee19&type=album|ep&fmt=json"
# Fetches, flattens and gets the titles to all releases
albums = fetch(url) \
.json() \
.then(lambda data: data.flatten(base=["releases"])[0]) \
.then(lambda data: [item.title for item in data]) \
.get_data()
assert {"Stoney", "Hollywood’s Bleeding", "beerbongs & bentleys"}.issubset(albums)
Installation
This package is available on pip
pip install jsj
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 jsj-0.3.4.tar.gz.
File metadata
- Download URL: jsj-0.3.4.tar.gz
- Upload date:
- Size: 6.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
720017d0777c1cf1de98275e073a4f2e7a50c7b2adf1525d58b6fdbce8f0d1a6
|
|
| MD5 |
6e6655bf35149e5b7f36bdc2439eef54
|
|
| BLAKE2b-256 |
6a3e27f45c8d01dec2ea3bf412826ac09c8d8af8df879d06009b061013dd18ca
|
File details
Details for the file jsj-0.3.4-py3-none-any.whl.
File metadata
- Download URL: jsj-0.3.4-py3-none-any.whl
- Upload date:
- Size: 5.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
80888c4b922eb653b2b7a6eb819be3b0a5f22174e784b38954053892a14d785c
|
|
| MD5 |
d767a8ea662b44773447dad2f18eed0a
|
|
| BLAKE2b-256 |
29bb805c0e492ab04497b393d6be5567c2026b70cd2dd422300d63c5e2085a6e
|