Skip to main content

Convert your JSON data to a valid Python object to allow accessing keys with the member access operator(.)

Project description

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

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

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

json2obj-1.0.2.tar.gz (3.1 kB view details)

Uploaded Source

File details

Details for the file json2obj-1.0.2.tar.gz.

File metadata

  • Download URL: json2obj-1.0.2.tar.gz
  • Upload date:
  • Size: 3.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.0.1 pkginfo/1.8.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for json2obj-1.0.2.tar.gz
Algorithm Hash digest
SHA256 a184cf48b8bb190805ffa283566e4d29562efd487f634858c86a48699ec83919
MD5 a1aa6905f2a03ff663702450d11db18c
BLAKE2b-256 4242edd06a2e656789854da686ac1309a5b2a4b31e7f331c2fca219ea27d9752

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