Skip to main content

A simple JSON string creator that takes whatever you have and transform it into a String

Project description

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 foobar.

pip install jsonwhatever

Usage

from jsonwhatever import jsonwhatever as  jw

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

class Dog:
  def __init__(self) -> None:
    self.id = 0
    self.name = 'perro'
    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,'juan',dog_a)
bytes_example = bytes(4)
bytearray_example = bytearray(4)

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

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

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

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

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

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

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

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

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

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

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

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

#prints {"crazy_list":[4,5,{"brand":"Ford","model":"Mustang","year":1964},8,"(5+9j)"]}
print(jw.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 985, 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(jw.jsonwhatever('name','john',False))

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

jsonwhatever-0.0.2.tar.gz (3.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

jsonwhatever-0.0.2-py3-none-any.whl (4.4 kB view details)

Uploaded Python 3

File details

Details for the file jsonwhatever-0.0.2.tar.gz.

File metadata

  • Download URL: jsonwhatever-0.0.2.tar.gz
  • Upload date:
  • Size: 3.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.8.10

File hashes

Hashes for jsonwhatever-0.0.2.tar.gz
Algorithm Hash digest
SHA256 d61a12e59f718016f66eb510a923fbf9be609aa15454985fc2ecd7afa5bcab3f
MD5 ca8128f69d8b4b289fc65bb0378f4049
BLAKE2b-256 a4b8f485edf6cff6fd935a55ee4d4b17e102cc95ea874d725be18747eea8be83

See more details on using hashes here.

File details

Details for the file jsonwhatever-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: jsonwhatever-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 4.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.8.10

File hashes

Hashes for jsonwhatever-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 4a0fc6b90284b7e8f2aa3b879cfc010926de8aa96c00ef8439abc2cb84d68d23
MD5 cccb032b17622b7ed7ecad5604e6d64b
BLAKE2b-256 a8d68276b0cbab69b8c850ca70117b8d1fe3907ecf61d0b7e7ba9491b14459c5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page