JSON2OBJ

json2obj

Allows you to transform JSON data into an object whose members can be queried using the member access operator. Unlike json.dumps in the standard library that returns a dictionary object, this library returns a JSONObjectMapper obje…


This content originally appeared on DEV Community and was authored by Owen Trump

json2obj

Allows you to transform JSON data into an object whose members can be queried using the member access operator. Unlike json.dumps in the standard library that returns a dictionary object, this library returns a JSONObjectMapper object. The attributes of these objects are defined by the contents of the JSON data provided to it

Installation

It can be installed using pip
pip install json2obj
Source code available at
https://github.com/trumpowen/json2obj

Examples


import datetime
from json2obj import JSONObjectMapper 

person = JSONObjectMapper("""{ "name" : "trumpowen" , "age" : 125 }""") 
person.name == "trumpowen" # true
person.age == 125 # true 
# replaces and overwrites 
person.name = {} 
person.name.first_name = "Wilkins" 
person.name.last_name = "Owen" 
person.name.other_names = ["Trump"]

# add new attribute. If this is not desired, you can initialize the object with readonly set to True. This will prevent the addition of new attributes and changing the values of existing attributes 
person.dob = datetime(1900, 12, 6) 
json_data = str(person) # returns a string representation 
json_as_dict = person.to_dict() # returns a dictionary representation 

Documentation

Use help(obj) , where obj is an instance of JSONObjectMapper


This content originally appeared on DEV Community and was authored by Owen Trump


Print Share Comment Cite Upload Translate Updates
APA

Owen Trump | Sciencx (2021-11-22T23:45:15+00:00) JSON2OBJ. Retrieved from https://www.scien.cx/2021/11/22/json2obj/

MLA
" » JSON2OBJ." Owen Trump | Sciencx - Monday November 22, 2021, https://www.scien.cx/2021/11/22/json2obj/
HARVARD
Owen Trump | Sciencx Monday November 22, 2021 » JSON2OBJ., viewed ,<https://www.scien.cx/2021/11/22/json2obj/>
VANCOUVER
Owen Trump | Sciencx - » JSON2OBJ. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/11/22/json2obj/
CHICAGO
" » JSON2OBJ." Owen Trump | Sciencx - Accessed . https://www.scien.cx/2021/11/22/json2obj/
IEEE
" » JSON2OBJ." Owen Trump | Sciencx [Online]. Available: https://www.scien.cx/2021/11/22/json2obj/. [Accessed: ]
rf:citation
» JSON2OBJ | Owen Trump | Sciencx | https://www.scien.cx/2021/11/22/json2obj/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.