Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Easier customization of JSON encoding. #24

Open
carljm opened this issue Feb 20, 2014 · 0 comments
Open

Easier customization of JSON encoding. #24

carljm opened this issue Feb 20, 2014 · 0 comments

Comments

@carljm
Copy link
Contributor

carljm commented Feb 20, 2014

I have cases where I want to be able to pass some custom objects (which are not JSON serializable by default) as properties of a mixpanel event, from various places in my code. The simplest and most flexible way to deal with this (such that it can automatically handle my object within a list, or standalone) is to create a JSONEncoder subclass that knows how to serialize my class, and then use that encoder class for the json.dumps call.

It's not currently too bad to do this - just requires subclassing EventTracker and overriding the _encode_params method. But this still requires duplicating some things I don't care about customizing - the base64-encoding, and the MIXPANEL_DATA_VARIABLE.

It would be nice if either there were a json_encoder_class class attribute on EventTracker, or a more fine-grained _params_to_json method. (Names up for debate).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant