Metadata-Version: 2.1
Name: json-np
Version: 0.0.6
Summary: Json serialization extended to dates, numpy arrays, and more
Author-email: Luca de Alfaro <luca@dealfaro.com>, Massimo Di Pierro <massimo.dipierro@gmail.com>
License: MIT License
        
        Copyright (c) 2017 Camio and 2023 Luca de Alfaro
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: Homepage, https://github.com/lucadealfaro/json_np
Project-URL: Bug Tracker, https://github.com/lucadealfaro/json_np/issues
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: Implementation :: CPython
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.7
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: numpy

# json_np

Json for numpy, or if you prefer, json no problems! 

**Authors:** Luca de Alfaro (luca@dealfaro.com) and Massimo Di Pierro 
(mdipierro@gmail.com)

This is a version of Json that can handle also: 
* Dates
* Sets
* numpy array
* bytes

There are two ways to use it. 

## Basic Usage

```
import json_np
import numpy as np

a = np.array([3, 4, 5])
s = json_np.dumps(a)
aa = json_np.loads(s)

```

Here, we have applied `json_np.dumps` to a numpy array, but we could equally 
well have used a datetime, a dictionary, a list, etc (nesting of such types is 
allowed).

## Class-Based Usage

You can also dump any object.
All object attributes, except those whose name begins with underscore (`_`), 
will be serialized. 
Optionally, if `serializable_only` is True, only objects that are 
instances of `Serializable`, or that are dates, numpy arrays,  will be 
serialized. 

The deserialization happens in the same class, if:
* the class can be loaded
* the class initializer has no required arguments.

If any of these two conditions is not met, the deserialization happens
using the `Serializable` class. 

```
from json_np import Serializable

class C(object):

    def __init__(self, a=8):
        super().__init__()
        self.a = a # Serialized
        self._b = 32 # Not serialized

c = C("hello")
s = json_np.dumps(c)
cc = json_np.loads(s)
```

Obviously, you should ensure that C contains compatible fields when it is 
deserialized, in case the code changed in the meantime. 

## History

This package was originally developed by Luca and Massimo at Camio, for 
Python2.  The work was open sourced.  The package was later ported to Python 3. 
The authors thank Camio for allowing the open-sourcing of the code. 
