gopyjson 0.1.2
GoPyJSON is a modification of the original json module in Python. It is designed to work like GoLang's json module.
Requires Python: >=3.6
Keywords: json,json2class,golangunmarshal,golangmarshal,class2json

# GoPyJSON

> Documentation coming soon...(doubt)

`GoPyJSON` is a modification of the original `json` module in Python which is written by **Bob Ippolito**.
GoPyJSON supports all the basic functionality by the json module and adds *more cream* to the top. *(sometimes things are just fixed by adding some more cream)*

Enough of that now lets get to the main thing..., `GoPyJSON` is built to *work* like the json module in GoLang.\
In Go we have `struct`s they are like classes in Python, but the json module in Python outputs a `dict` aka a dictionary and it has its upsides and downsides.

## What we all face with those `dict`s is that:
1. They have all the objects mapped to them, which means we have **0** control in what we need and what to ignore.
2. They are annoying like who is crazy enough to write this - `jsondict['val']['d']['ot'][...]...`, well u have to do the same with classes but its a bit different.
3. We cannot choose if we want the raw json or a `dict`

## What can GoPyJSON do?

`GoPyJSON` works a bit differently, in order to determine stuff and dynamically assign stuff we get help from `metaclasses` *(a completely new topic? Its a bit complicated so if you are new then its not recommended to look more into it...)*, the implementation checks for classes *derived* from this metaclass. Also when objects are returned they are locked that means the `__setattr` funtion of the object is set to do nothing.\
⋄ How does it work and what if I dont define a class to map to?\
A. GoPyJSON looks for classes derived from a metacless defined in the *module* so if a class is not found you will get one of the two possible outputs.\
1 - A `dict` this is the default when no classes are found.\
2 - A `str` this is when you set `raw_json` to `True`, this can later be used in `loads` to convert to a `dict` or a class.

## How to install?

Simply run: `pip install gopyjson`

## Playing around

The [test.py](test.py) has a `json` string to load, dum and then load again...

If you run [test.py](test.py) without changing it you will see the following output. *(obviously the hex of the memory address will be different)*

```
-- Load json
Json string                  -
{
        "bool": true,
        "int": 10,
        "float": 6.9,
        "str": "Henlo World!",
        "array": [
                "Henlo",
                "world"
        ],
        "object": {
                "val": "Wow nested objects are returned as dict if default not specified!"
        },
        "rawobject": [{
                "val": null
        }, {
                "val": true
        }, {
                "val": false
        }],
        "pobject": {
                "val": "Wow nested objects are returned as objects if default is a Struct type, noice!"
        },
        "paobject": [{
                "val": "Wow nested objects are returned as a list objects if default is a Struct type and the json value is a list, noice! [1]"
        }, {
                "val": "Wow nested objects are returned as a list objects if default is a Struct type and the json value is a list, noice! [2]"
        }, {
                "val": "Wow nested objects are returned as a list objects if default is a Struct type and the json value is a list, noice! [3]"
        }]
}
Json - "bool"              -    True

Json - "int"               -    10

Json - "float"             -    6.9

Json - "str"               -    Henlo World!

Json - "array"             -    ['Henlo', 'world']

Json - "object"            -    {'val': 'Wow nested objects are returned as dict if default not specified!'}

Json - "rawobject"         -    [{"val": null}, {"val": true}, {"val": false}]

Json - "pobject"           -    <__main__.ParsedObject object at 0x0000016A04E78FC0>

Json - "pobject.val"       -    Wow nested objects are returned as objects if default is a Struct type, noice!

Json - "paobject"          -    [<__main__.ParsedObject object at 0x0000016A04E6E0C0>, <__main__.ParsedObject object at 0x0000016A04E6E140>, <__main__.ParsedObject object at 0x0000016A04E6E1C0>]

Json - "paobject[0].val"   -    Wow nested objects are returned as a list objects if default is a Struct type and the json value is a list, noice! [1]

Json - "paobject[1].val"   -    Wow nested objects are returned as a list objects if default is a Struct type and the json value is a list, noice! [2]

-- Dump json
{"bool": true, "int": 10, "float": 6.9, "str": "Henlo World!", "array": ["Henlo", "world"], "object": {"val": "Wow nested objects are returned as dict if default not specified!"}, "rawobject": "[{\"val\": null}, {\"val\": true}, {\"val\": false}]", "pobject": {"val": "Wow nested objects are returned as objects if default is a Struct type, noice!"}, "paobject": [{"val": "Wow nested objects are returned as a list objects if default is a Struct type and the json value is a list, noice! [1]"}, {"val": "Wow nested objects are returned as a list objects if default is a Struct type and the json value is a list, noice! [2]"}, {"val": "Wow nested objects are returned as a list objects if default is a Struct type and the json value is a list, noice! [3]"}]}

-- Raw json Loads
[<__main__.ParsedObject object at 0x0000016A04E78CC0>, <__main__.ParsedObject object at 0x0000016A04E78C00>, <__main__.ParsedObject object at 0x0000016A04E78B80>]

None

True

False
```