Question: I'm new to python and having an issue with decoding JSON to a Python Class. For example:

If we had a python class representing persons:

```
Class Person:
    def __init__(self, Fname, Lname, Age):
        self.FirstName = Fname
        self.LastName = Lname
        self.Age = Age

```

Now I have a JSON and let us say for example I got it from a web service body or something and it is like this:

```
JsonOBJ = {"FirstName":"Mostafa","LastName":"Mohamed","Age":"26"}

```

I need to decode that JSON to have an object of type Person filled with values and to access its properties like:

```
Obj.FirstName

```

Thanks.

Answer: 
Is there a reason you need full class implementation? If you're simply looking to access attributes by key not using a dict, you can create a namedtuple. 

```
from collections import namedtuple

def dict_to_namedtuple(d):
    # This sets up a namedtuple called 'Person' with the provided keys
    # It then creates the namedtuple with the unpacked dict
    return namedtuple('Person', d.keys())(**d)

d = {"FirstName":"Mostafa","LastName":"Mohamed","Age":"26"}
person = dict_to_named_tuple(d)

print(person)
# Person(FirstName='Mostafa', LastName='Mohamed', Age='26')

print(person.FirstName)
# 'Mostafa'

```
If you already have the JSON string as a Python dictionary you can simply expand it using `**`:

```
p = Person(**{'Fname': 'a', 'Lname': 'b', 'Age': 11})
print(p.FirstName)
# a

```

If you don't, another option is to create a class method that knows how to create a `Person` object from a JSON string. This way the creation logic is somehow encapsulated from the calling code:

```
class Person:
    def __init__(self, Fname, Lname, Age):
        self.FirstName = Fname
        self.LastName = Lname
        self.Age = Age

    @classmethod
    def from_json_string(cls, json_string):
        dict_obj = json.loads(json_string)
        return cls(**dict_obj)

p = Person.from_json_string('{"Fname": "a", "Lname": "b", "Age": 11}')

print(p.FirstName)
# a

```

Keep in mind that both the approaches I showed are using `**` to expand the dictionary to single arguments to `Person.__init__`. This implies that the keys must match the arguments that `__init__` expects. If they don't, you need to pass the correct key/value to `__init__` instead of using `**`.