Skip to main content

jsonwhatever

jsonwhatever is a library that creates a string, just putting a name and the object as arguments.

Installation

Use the package manager pip to install jsonwhatever.

pip install jsonwhatever

Usage

from jsonwhatever import JsonWhatEver

thisdict = {
  "brand": "Ford",
  "model": "Mustang",
  "year": 1964
}

class Dog:
  def __init__(self) -> None:
    self.id = 0
    self.name = 'fido'
    self.size = 5.3

class Person:
  def __init__(self, id, name, dog) -> None:
    self.id = id
    self.name = name
    self.dog = dog

dog_a = Dog()

complex_number = 5+9j
list_b = [4,5,6,8]
list_a = [2,3,'hello',7,list_b]
list_c = [4,5,thisdict,8,complex_number]
empty_list = []
none_var = None
bool_var = True
set_example_empty = set()
set_example = {1,2,3,4}
class_example = Person(9,'john',dog_a)
bytes_example = bytes(4)
bytearray_example = bytearray(4)

#########################
jsonwe = JsonWhatEver()
#########################

#prints {"list_example":[4,5,6,8]}
print(jsonwe.jsonwhatever('list_example',list_b))

#prints {"name":"john"}
print(jsonwe.jsonwhatever('name','john'))

#prints {"size":1.7}
print(jsonwe.jsonwhatever('size',1.7))

#prints {"empty_list":[]}
print(jsonwe.jsonwhatever('empty_list',empty_list))

#prints {"none_example":null}
print(jsonwe.jsonwhatever('none_example',none_var))

#prints {"boolean":True}
print(jsonwe.jsonwhatever('boolean',bool_var))

#prints {"empty_set":[]}
print(jsonwe.jsonwhatever('empty_set',set_example_empty))

#prints {"set_example":[1,2,3,4]}
print(jsonwe.jsonwhatever('set_example',set_example))

#prints {"brand":"Ford","model":"Mustang","year":1964}
print(jsonwe.jsonwhatever('thisdict',thisdict))

#prints {"id":9,"name":"juan",{"id":0,"name":"perro","size":5.3}}
print(jsonwe.jsonwhatever('person_class',class_example))

#prints {"bytes_example":"b'\x00\x00\x00\x00'"}
print(jsonwe.jsonwhatever('bytes_example',bytes_example))

#prints {"bytearray_example":"b'\x00\x00\x00\x00'"}
print(jsonwe.jsonwhatever('bytearray_example',bytearray_example))

#prints {"crazy_list":[4,5,{"brand":"Ford","model":"Mustang","year":1964},8,"(5+9j)"]}
print(jsonwe.jsonwhatever('crazy_list',list_c))

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

Things to know about

  1. You always have to put some name on the first argument of the jsonwhatever function, otherwise the function will return a string that does not match the json standard.

  2. The jsonwhatever function can allow recursivity on a list until the level 800, after that, it will rise the RecursionError exception.

  3. The jsonwhatever function allows you to recieve a json without the curly braces at the beginning and in the end of the phrase. By default it will be in True.

#prints "name":"john"
print(jsonwe.jsonwhatever('name','john',False))

#prints {"name":"john"}
print(jsonwe.jsonwhatever('name','john',True))
print(jsonwe.jsonwhatever('name','john'))

Release Notes

  1. The main structure in the library is an object class.
  2. Now a few attributes are private, like the datatypes.
  3. The class can detect the ammount of levels of recursions.
  4. The maximum level of recursions are 800, after that it will raise a RecursionError exception.
  5. We fixed a bug in the recursion counter, that stops the recursion after the number 800.
  6. The Big O notation is O(n), but after 2 million items the behavior stops being linear.

Metadata

Release files for jsonwhatever 1.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for jsonwhatever 1.1.1
File Size Uploaded
jsonwhatever-1.1.1.tar.gz 4.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for jsonwhatever 1.1.1
File Interpreter ABI Platform
jsonwhatever-1.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 9.5 kB

Release files / jsonwhatever-1.1.1.tar.gz

Download URL jsonwhatever-1.1.1.tar.gz
Size 4.4 kB
Tags Source
SHA-256 checksum
How to use checksums
c2f76b070e1c302300cf3f9901eb29d4c6da404c4d6b0a63ac9e83f140d432b3
BLAKE2b-256 checksum
How to use checksums
8836f206f7292cb70356ced3d5b84b68688ef77a31bf73b1a9b234852ac4a937
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.8.10

Release files / jsonwhatever-1.1.1-py3-none-any.whl

Download URL jsonwhatever-1.1.1-py3-none-any.whl
Size 5.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b30e85214f4df22a19e56f1d0730b415623daf44c28a6265781c7b8eec5bceb3
BLAKE2b-256 checksum
How to use checksums
43bec35cf7f8458f61b04f87233745554cb22110c72ae63d59b00bf0ab867acb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.8.10

Release history Release notifications | RSS feed

This release

1.1.1 This release

2 release files

1.1.0

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page