JSONx - Easy JSON wrapper packed with features.

Related tags

JSONpythonjson
Overview

🈷️ 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

Clone this file into your project folder.

Add from db import JSONx to the top of your project.

📄 Docs

db.set(key: str, value, *, pathmagic="")

Sets the key to the value in the JSON.

if the pathmagic kwarg is given, it will spit it by the +'s and make dicts(or use existing ones) until it finishes, then it will set the value to the key in the last dict.

Note that the pathmagic kwarg will override its path if it isnt a dict.

db.get(key: str, *, default=None, pathmagic="")

Returns the value of the key in the json, if the key isn't set in the json, it returns the default kwarg.

if the pathmagic kwarg is given, it will spit it by the +'s and follow the path in it in the JSON data, it will return the default kwarg if the path is empty or has a value that isnt a dict.

db.all()

Returns all the JSON data.

db.rem(key: str, *, pathmagic="")

Removes the key and value pair from the JSON.

Note that this will not do anything if the key isn't set in the JSON or the path is invalid.

if the pathmagic kwarg is given, it will spit it by the +'s and follow the path in it in the JSON data, then it will remove the key and value pair.

db.nuke()

Deletes everything in the JSON.

Use with caution.

📘 Examples

Assume that the db.json file is empty

db.set()

Normal usage

Code

from db import JSONx

db = JSONx("db.json")

db.set("test", 123)

data = db.all()

print(data)

Output

{'test': 123}

Using with pathmagic kwarg

Code

from db import JSONx

db = JSONx("db.json")

db.set("test", 123, pathmagic="a+b+c")

data = db.all()

print(data)

Output

{'a': {'b': {'c': {'test': 123}}}}

db.get()

Normal usage

Code

from db import JSONx

db = JSONx("db.json")

db.set("test", 123)

data = db.get("test")

print(data)

Output

123

Using without default kwarg

Code

from db import JSONx

db = JSONx("db.json")

data = db.get("test")

print(data)

Output

None

Using with default kwarg

Code

from db import JSONx

db = JSONx("db.json")

data = db.get("test", default=123)

print(data)

Output

123

Using with pathmagic kwarg

Code

from db import JSONx

db = JSONx("db.json")

db.set("test", 123, pathmagic="a+b+c")

data = db.get("test", pathmagic="a+b+c")

print(data)

Output

123

db.rem()

Normal usage

Code

from db import JSONx

db = JSONx("db.json")

db.set("test", 123)

data = db.all()

print(data)

db.rem("test")

data = db.all()

print(data)

Output

{'test': 123}
{}

Using with pathmagic kwarg

Code

from db import JSONx

db = JSONx("db.json")

db.set("test", 123, pathmagic="a+b+c")

data = db.all()

print(data)

db.rem("test", pathmagic="a+b+c")

data = db.all()

print(data)

Output

{'a': {'b': {'c': {'test': 123}}}}
{'a': {'b': {'c': {}}}}
You might also like...
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

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

 simdjson : Parsing gigabytes of JSON per second
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 parse JSON 4x faster than RapidJSON and 25x faster than JSON for Modern C++.

import json files directly in your python scripts
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

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.

Convert your subscriptions csv file into a valid json for Newpipe!
Convert your subscriptions csv file into a valid json for Newpipe!

Newpipe-CSV-Fixer Convert your Google subscriptions CSV file into a valid JSON for Newpipe! Thanks to nikcorg for sharing how to convert the CSV into

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

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

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.

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

Comments
  • Sourcery refactored main branch

    Sourcery refactored main branch

    Branch main refactored by Sourcery.

    If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.

    See our documentation here.

    Run Sourcery locally

    Reduce the feedback loop during development by using the Sourcery editor plugin:

    Review changes via command line

    To manually merge these changes, make sure you're on the main branch, then run:

    git fetch origin sourcery/main
    git merge --ff-only FETCH_HEAD
    git reset HEAD^
    

    Help us improve this pull request!

    opened by sourcery-ai[bot] 1
Releases(v1.2.0)
No more boilerplate to check and build a Python object from JSON.

JSONloader This module is for you if you're tired of writing boilerplate that: builds a straightforward Python object from loaded JSON. checks that yo

3 Feb 05, 2022
Ibmi-json-beautify - Beautify json string with python

Ibmi-json-beautify - Beautify json string with python

Jefferson Vaughn 3 Feb 02, 2022
A Python tool that parses JSON documents using JsonPath

A Python tool that parses JSON documents using JsonPath

8 Dec 18, 2022
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
Make JSON serialization easier

Make JSON serialization easier

4 Jun 30, 2022
Marshall python objects to and from JSON

Pymarshaler - Marshal and Unmarshal Python Objects Disclaimer This tool is in no way production ready About Pymarshaler allows you to marshal and unma

Hernan Romer 9 Dec 20, 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
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 07, 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
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 01, 2021
JSONManipulator is a Python package to retrieve, add, delete, change and store objects in JSON files.

JSONManipulator JSONManipulator is a Python package to retrieve, add, delete, change and store objects in JSON files. Installation Use the package man

Andrew Polukhin 1 Jan 07, 2022
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 :).

Arttu Väisänen 1 Jan 30, 2022
A JSON API for returning Godspeak sentences. Based on the works of Terry A Davis (Rest in Peace, King)

GodspeakAPI A simple API for generating random words ("godspeaks"), inspired by the works of Terrence Andrew Davis (Rest In Peace, King). Installation

Eccentrici 3 Jan 24, 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
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
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
Console to handle object storage using JSON serialization and deserealization.

Console to handle object storage using JSON serialization and deserealization. This is a team project to develop a Python3 console that emulates the AirBnb object management.

Ronald Alexander 3 Dec 03, 2022
Fileson - JSON File database tools

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

Joonas Pihlajamaa 2 Feb 02, 2022
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