json with datetimes and custom types
Project description
JSON plus types
===============
Uses builtin json. but adds a lookup dictionary with functions that encode/decode specific types.
TO INSTALL
----------
$ pip install jsonplustypes
default _TYPE_FUNCS dict holds:
_TYPE_FUNCS{
datetime.datetime: encode_datetime,
"DATETIME": decode_datetime,
float:encode_float
}
where encode ande decode datetime functions:
def encode_datetime(date_object):
date_string = datetime.datetime.strftime(date_object, _DATE_FORMAT)
return {
_TYPE_TAG:"DATETIME",
_VALUE_TAG:date_string
}
def decode_datetime(date_string):
return datetime.datetime.strptime(date_string, _DATE_FORMAT)
the github repo holds a reference javascript implementation of the same json serialization/deserialization
===============
Uses builtin json. but adds a lookup dictionary with functions that encode/decode specific types.
TO INSTALL
----------
$ pip install jsonplustypes
default _TYPE_FUNCS dict holds:
_TYPE_FUNCS{
datetime.datetime: encode_datetime,
"DATETIME": decode_datetime,
float:encode_float
}
where encode ande decode datetime functions:
def encode_datetime(date_object):
date_string = datetime.datetime.strftime(date_object, _DATE_FORMAT)
return {
_TYPE_TAG:"DATETIME",
_VALUE_TAG:date_string
}
def decode_datetime(date_string):
return datetime.datetime.strptime(date_string, _DATE_FORMAT)
the github repo holds a reference javascript implementation of the same json serialization/deserialization
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
jsonplustypes-0.6.tar.gz
(1.6 kB
view hashes)