Code Monkey home page Code Monkey logo

jsonwriter's Introduction

JSON Writer

Easy package to write JSON files

About

jsonwriter is an easy JSON writer, when i say easy i mean super easy

Made by Nawaf Alqari in 2021

Installation

PIP

pip install jsonwriter

Examples

Initialize your file:

If you set autosave to True every change you make will be automatically saved
from jsonwriter import file
file = file('filename.json', autosave=True)

file.set('key', 'value') # This will be saved automatically 
If you don't use autosave you have to add file.save() whenever you want to save your changes
from jsonwriter import file
file = file('filename.json', autosave=False)

file.set('key', 'value')
file.set('key2', 'value2')
file.save() # Now, it will be saved

Functions

Let's say this is our file content:

{
   "name": "Nawaf",
   "age": 10
}

get(key)

file.get('name') # Will return Nawaf
file.get('age') # Will return 10

set(key, value)

file.set('Skills', ['Sleeping', 'Coding'], indent=3)
# indentation will make it more readable
# 3 is recommended/default value

# set() Can also update values
file.set('age', 100)

File will get updated to

{
   "name": "Nawaf",
   "age": 100,
   "Skills": [
      "Sleeping",
      "Coding"
   ]
}

If we set the indentation to 0 this is what we will get

{"name": "Nawaf", "age": 100, "Skills": ["Sleeping", "Coding"]}

remove(key)

file.remove('name') # This will just remove "name": "Nawaf"

clear()

file.clear() # Warning! This will remove everything from your file

hasKey(key)

file.hasKey('age') # return True

hasValue(value)

file.hasValue(10) # return True

hasAll(key or value)

file.hasAll('age') # return True
file.hasAll(10) # return True

Attributes

from jsonwriter import file
file = file('filename.json', autosave=True)

print(file.content)
# This will show your file content
# Note: if you are not using autosave this will show all the changes, even if they are not saved

print(file.keys)
# This will show all the keys

print(file.values)
# This will show all the values

jsonwriter's People

Contributors

nawafalqari avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.