Coder Social home page Coder Social logo

znjson's People

Contributors

pythonfz avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Forkers

jr-1991

znjson's Issues

Rename `znjson.ZnEncoder` to `znjson.Encoder` ?

ZnJSON/znjson/main.py

Lines 7 to 16 in 553e366

class ZnEncoder(json.JSONEncoder):
def default(self, o: Any) -> Any:
config.sort()
for converter in config.ACTIVE_CONVERTER:
if converter() == o:
return converter().encode(o)
raise TypeError(f"Object of type {type(o).__name__} is not JSON serializable")
class ZnDecoder(json.JSONDecoder):

Allow to use converters directly

Currently you have to do:

znjson.config.register(CustomConverter)
json.dump(data, cls=znjson.ZnEncoder)

but maybe you only want to use a specific converter which could look something like:

json.dump(data, cls=znjson.ZnEncoder.from_converter(CustomConverter, allow_default=True)) # this could be a list of converters
# or
json.dump(data, cls=CustomConverter) # this would allow only one converter

generalize serializing scheme

To avoid issues when e.g. de-serializing a dict {"Path": "this is some string"} which should return a dict and not a Path object,
it would be possible to serialize all objects to the dict {<type>: val} which would yield{"dict": {"Path": "this is some string"}} and therefore can not be confused with {"Path": "this is some string"}.

Add NumpyAdvancedConverter

A numpy (and maybe also pandas) converter could also convert to lists instead of binary.
This could be useful for small arrays.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.