JSON file builder
Project description
json-build
json-build is a package that allows developers to build and save JSON files quickly.
Installation
pip install json-build
Create a new JSON object to build upon
from json_build import JSON_Object
new_json = JSON_Object(outer=[])
# 'outer' argument is optional
# if 'outer=[]' is passed it will wrap the JSON object in an array (Python list)
# otherwise, it will be a JSON object (Python dictionary)
Nest objects inside the JSON object
new_json.add_object(
unique_name="people",
keyword="people",
data={},
)
new_json.add_object(
unique_name = 'person_1',
keyword = 'person1',
data = {"first_name": "Michael", "last_name": "Myers"},
parent='people',
)
new_json.add_object(
unique_name = 'relative_1',
keyword = 'relative',
data = {"first_name": "Laurie", "last_name": "Strode", "relation": "Sister"},
parent = 'person_1'
)
new_json.add_object(
unique_name = 'person_2',
keyword = 'person2',
data = {"first_name": "Jason", "last_name": "Voorhees"},
parent='people',
)
new_json.add_object(
unique_name = 'relative_2',
keyword = 'relative',
data = {"first_name": "Pamela", "last_name": "Voorhees", "relation": "Mother"},
parent = 'person_2'
)
new_json.add_object(
unique_name = 'movies',
keyword = 'movies',
data = [
'Halloween',
'Friday the 13th',
'Nightmare on Elm Street',
],
)
# 'parent' argument is optional; if unpassed, the object will be added to the JSON object's first level
# Note that 'parent' uses the unique_name of the parent object, and not the keyword
Create the JSON object
new_json.create()
Save the JSON object to a file
new_json.save(file_name="killer_names", location_path="C:/Users/fkrueger/Desktop/")
# 'location_path' argument is optional; if unpassed it will save the file to the root of your local project
Resultant JSON object
[
{
"people": {
"person1": {
"first_name": "Michael",
"last_name": "Myers",
"relative": {
"first_name": "Laurie",
"last_name": "Strode",
"relation": "Sister"
}
},
"person2": {
"first_name": "Jason",
"last_name": "Voorhees",
"relative": {
"first_name": "Pamela",
"last_name": "Voorhees",
"relation": "Mother"
}
}
},
"movies": [
"Halloween",
"Friday the 13th",
"Nightmare on Elm Street"
]
}
]
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
json-build-1.0.2.tar.gz
(4.1 kB
view hashes)
Built Distribution
Close
Hashes for json_build-1.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ce44ebf51476f321fcb7c2e4ec1f3a2ac81fa9df6f4fa3fecb957a55a344d6bc |
|
MD5 | f2c5f43d37658042e56972687ba2c01a |
|
BLAKE2b-256 | 5e0b6b359c7d1d90522362187c419286848e20700d094892ca92d26b5c225b40 |