Skip to content

Conversation

Komnomnomnom
Copy link
Contributor

This adds a default_handler param to to_json, which if passed must be a callable which takes one argument (the object to convert) and returns a serialisable object. The default_handler will only be used if an object cannot otherwise be serialised.

Note right now the JSON serialiser has direct handling for:

  • Python basic types bool, int, long, float.
  • Python containers dict, list, tuple and set.
  • Python byte and unicode strings.
  • Python decimal.
  • Python datetime and date.
  • Python None.
  • Numpy arrays.
  • Numpy scalars
  • NaN and NaT
  • Pandas Index, Series, DataFrame and Timestamp
  • any subclasses of the above.

If an object is not recognised the fallback behaviour with this PR would be:

  1. if a toDict method is defined by the unrecognised object that
    will be called and its returned dict will be JSON serialised.
  2. if a default_handler has been passed to to_json that will
    be called to convert the object.
  3. otherwise an attempt is made to convert the object to a dict by
    iterating over its attributes.

@jreback
Copy link
Contributor

jreback commented Oct 7, 2013

didn't this have an original issue? (or was that on the time serializatino?)

if not, just reference this issue in the release notes

passed on windows?

@jreback jreback merged commit a3997c3 into pandas-dev:master Oct 7, 2013
@jreback
Copy link
Contributor

jreback commented Oct 7, 2013

thanks.....(I updated the release notes)...and confirmed windows...

@Komnomnomnom Komnomnomnom deleted the json-default-handler branch October 7, 2013 13:57
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

Successfully merging this pull request may close these issues.

2 participants