Package: pyjsonic
python-jsonicPython bindings forJsonicJSON reader library.InstallPIP:pipinstallpyjsonicGit:gitclonehttps://github.com/rohanrhu/python-jsoniccdpython-jsonic
pythonsetup.pyinstallUsageImportimportjsonicTypes and FunctionsFunction: from_fileRead file and returnsJsonic()object.root=jsonic.from_file("file.json")Type: Jsonicroot=jsonic.Jsonic("[1, 2, 3, 4]")Member: Jsonic.typeType member is useable for checking object and array types. Except object and array types, you will get regular pythonstr,float,boolorjsonic.Nullobject.Type CheckingTypesjsonic.TYPE_OBJECTjsonic.TYPE_ARRAYJsonic.typeis useable for objects or arrays. Object and array values returns asJsonic()objects. Null values returns asJsonic.Nullobject. Otherwise it returns as regular python types.Member: Jsonic.versionVersion of python-jsonic.Member: Jsonic.jsonJSON String.Type: Jsonic.NullJSON Null type.Method: root()Returns JSON root's value ifroot.typeis not an array or object. Otherwise it returns None.root=jsonic.Jsonic("1234")print(root.root())# 1234root=jsonic.Jsonic("\"foo\"")print(root.root())# fooroot=jsonic.Jsonic("true")print(root.root())# Trueroot=jsonic.Jsonic("null")print(root.root())# jsonic.Nullroot=jsonic.Jsonic("{}")print(root.root())# Noneprint(root.type)# jsonic.TYPE_OBJECTroot=jsonic.Jsonic("[]")print(root.root())# Noneprint(root.type)# jsonic.TYPE_ARRAYMethod: len()Gets length of array.Method: key(key)Returns the key's value.Method: item(index)Returns item of an index on array.Method: iterItem(index=0)Iterates array item from last iterated item times index.root=jsonic.Jsonic("[1, 2, 3, 4]")print(array.iterItem())# 1print(array.iterItem())# 2print(array.iterItem(1))# 4print(array.iterItem())# Nonearray.reset()print(array.iterItem())# 1Method: iterKey(key)Iterates object key from last iterated object.root=jsonic.Jsonic("{\"a\": 1,\"b\": 2,\"c\": 3,\"d\": 4}")print(array.iterKey("a"))# 1print(array.iterKey("b"))# 2print(array.iterKey("c"))# 3print(array.iterKey("b"))# Nonearray.reset()print(array.iterKey("b"))# 2Method: reset()Resets iteration current.ExampleAn example for reading JSON dataimportjsonicroot=jsonic.from_file("heroes.json")print("Root Type:%d"%root.type)print("Squad:%s"%root.iterKey("squadName"))print("Hometown:%s"%root.iterKey("homeTown"))print("Formed:%d"%root.iterKey("formed"))print("Active:%d"%root.iterKey("active"))members=root.iterKey("members")print("Members: (%dtotal)"%members.len())whileTrue:member=members.iterItem()ifnotmember:breakname=member.iterKey("name")age=member.iterKey("age")powers=member.iterKey("powers")print("\tName:%s"%name)print("\tAge:%s"%age)print("\tPowers (%dtotal):"%powers.len())whileTrue:power=powers.iterItem()ifnotpower:breakprint("\t\t%s"%power)print()Example JSON (heroes.json):{"squadName":"Super hero squad","homeTown":"Metro City","formed":2016,"secretBase":"Super tower","active":true,"members":[{"name":"Molecule Man","age":29,"secretIdentity":"Dan Jukes","powers":["Radiation resistance","Turning tiny","Radiation blast"]},{"name":"Madame Uppercut","age":39,"secretIdentity":"Jane Wilson","powers":["Million tonne punch","Damage resistance","Superhuman reflexes"]},{"name":"Eternal Flame","age":1000000,"secretIdentity":"Unknown","powers":["Immortality","Heat Immunity","Inferno","Teleportation","Interdimensional travel"]}]}Syntax CheckingThis library does not check JSON syntax, so you may getSIGSEGVor maybe infinite loops forcorrupt JSONs. Likewise in some cases of corrupt JSONs, it would work as properly.PerformanceThere are some example JSONs and reading examples inexamples/folder for profiling the performance.C LibraryYou can useJsonicJSON reader library for C/C++.LicenseMIT