Package: smartjson
BigQuery | Google cloud<==>Python libraries to convert class to json, object and dict to Json and Json to Object (SmartJson)SmartJsonis a simple tool to convert any class or dict to JSON and convert json to Object.DocumentationFeatures:version (2.0.3)update list serializationversion (2.0.2)Fix scriptAdd script support enumeration (enum)Already support type : *class*date*datetime*set*OrderedDict*deque*list*int*float*bool*complex*tuple*str*dict*bytes*Noneex :fromenumimportEnum,IntEnumfromscriptsimportSmartJsonclassLoggerLevel(Enum):CRITICAL='CRITICAL'ERROR='ERROR'WARNING='WARNING'INFO='INFO'DEBUG='DEBUG'NOTSET="NOTSET"classStatus(IntEnum):success=0failure=1print(SmartJson({'Log':LoggerLevel,'Stat':Status}).serialize())output :{"Log":[{"CRITICAL":"CRITICAL","DEBUG":"DEBUG","ERROR":"ERROR","INFO":"INFO","NOTSET":"data","WARNING":"WARNING"}],"Stat":[{"failure":1,"success":0}]}version (2.0.1)Fix scriptupdate complex serializationAdd new method (serializeToJsonFile)convert your class to json filedict:Default parameter directory="output", filename="smart.json"class:Default parameter directory="output", filename="className.json"ex :SmartJson(Test()).serializeToJsonFile(directory="yourPath", filename="MyFileName.json")SmartJson(Test()).serializeToJsonFile() :=> (output) :=> outpout/Test.jsonversion (2.0.0)Support:ClassdatedatetimesetOrderedDictdequelistintfloatboolcomplextuplestrdictbytesNoneInstallsmartjsonis released on PyPI, so all you need is:$ pip install smartjsonTo upgrade to latest version:$ pip install --upgrade smartjsonUsageRequirementsPython >= 2.7must be installed.Parametersclass or object or dict:  you want to convert to jsonProject structure:scripts- source code of a packageexample.py- working examplesContributeIf unsure, open an issue for a discussionCreate a forkMake your changeMake a pull requestHappy contribution!EXAMPLEClassimportdatetimefromcollectionsimportdeque,OrderedDictfromscripts.__smart_json__importSmartJsonclassTest:def__init__(self):self.test="none"self.id=2self.date=datetime.datetime.now()self.tuple=[((1,'a'),(2,'b'))]data={"int":1,"str":"SmartJson","bytes":"pip install smartjson".encode("utf-8"),"date":datetime.date(2010,1,1),"datetime":datetime.datetime(2020,1,1,18,30,0,500),"pull":Test(),"set":(["1",12,datetime.datetime.now()]),"list":[datetime.datetime.now(),Test()],"ordereddict":OrderedDict([("b",OrderedDict([("b",Test()),("a",datetime.datetime.now())])),("a",OrderedDict([("b",1),("a",[((1,'a'),(datetime.datetime.now(),'b'))])])),]),"deque":deque([deque([1,2]),deque([3,4]),])}classPull:def__init__(self):self.id=2self.title="Iam pull"self.author="Joel O."self.subPull=Pull.SubPull()self.data=dataself.date=datetime.datetime.now()self.list=[1,datetime.datetime.now(),Pull.SubPull()]classSubPull:def__init__(self):self.subId=3self.subTitle="I am sub title"self.subAuthor="OKJ."self.date=datetime.date(2010,1,1)# Examplemy_json=SmartJson(data).serialize()print(my_json)Output:{"bytes":"pip install smartjson","date":"2010-01-01","datetime":"2020-01-01 18:30:00.000500","deque":{"1":2,"3":4},"int":1,"list":["2019-10-01 19:39:01.916122",{"date":"2019-10-01 19:39:01.916122","id":2,"test":"none","tuple":[[[1,"a"],[2,"b"]]]}],"ordereddict":{"a":{"a":[[[1,"a"],["2019-10-01 19:39:01.916122","b"]]],"b":1},"b":{"a":"2019-10-01 19:39:01.916122","b":{"date":"2019-10-01 19:39:01.916122","id":2,"test":"none","tuple":[[[1,"a"],[2,"b"]]]}}},"pull":{"date":"2019-10-01 19:39:01.916122","id":2,"test":"none","tuple":[[[1,"a"],[2,"b"]]]},"set":["1",12,"2019-10-01 19:39:01.916122"],"str":"SmartJson"}Json to ObjectobjFromFile = smart_json.toObjectFromFile("jobs.json")
obj = smart_json.toObject('{"people":[{"name":"Scott", "website":"stackabuse.com", "from":"Nebraska"}]}')
obj2 = smart_json.toObject({'item': 'Beer', 'cost': '£4.00'})

print(obj2.item, obj2.cost)
print(objFromFile.job.item.another.precision)
print(obj.people[0].name, obj.people[0].website)

# Beer £4.00
# 99.56
# Scott stackabuse.comFor support or coffee :)Author :Koffi Joel O.