Skip to content

An additional option to allow the the non-encoding of python tuples #6

Closed
wants to merge 10 commits into from

3 participants

@Singletoned

I added an option to the JSONEncoder to allow tuples to not be automatically encoded to arrays, for the use case when you need to preserve the difference between tuples and lists (in this case you can now encode tuples to a custom object using the default() method).

I added a basic test (tests/test_tuple.py) and checked that all the other tests ran.

Unfortunately I couldn't add it into the _speedups.c, so I addd a check to iterencode that if this option has been changed, it shouldn't use the speedups.

Yours

Ed

@etrepum
simplejson member
etrepum commented Sep 4, 2011

This looks like a good idea, but I think I will do the implementation differently. Also, unittest.skipUnless wasn't added until Python 2.7 so you can't skip the test that way.

@etrepum
simplejson member
etrepum commented Sep 4, 2011

Actually, I don't think that being able to remove tuple from the array encoding is very useful... but encoding namedtuple as an object seems like the right thing to do. To support people who depended on the old behavior, there should also be a flag to turn this off.

@etrepum
simplejson member
etrepum commented Sep 4, 2011
@etrepum etrepum closed this Sep 4, 2011
@jperkin jperkin pushed a commit to joyent/pkgsrc that referenced this pull request Dec 9, 2013
wiz Update to 2.2.1:
Version 2.2.1 released 2011-09-06

* Fix MANIFEST.in issue when building a sdist from a sdist.
  simplejson/simplejson#16

Version 2.2.0 released 2011-09-04

* Remove setuptools requirement, reverted to pure distutils
* use_decimal default for encoding (dump, dumps, JSONEncoder) is now True
* tuple encoding as JSON objects can be turned off with new
  tuple_as_array=False option.
  simplejson/simplejson#6
* namedtuple (or other tuple subclasses with _asdict methods) are now
  encoded as JSON objects rather than arrays by default. Can be disabled
  and treated as a tuple with the new namedtuple_as_object=False option.
  simplejson/simplejson#6
* JSONDecodeError is now raised instead of ValueError when a document
  ends with an opening quote and the C speedups are in use.
  simplejson/simplejson#15
* Updated documentation with information about JSONDecodeError
* Force unicode linebreak characters to be escaped (U+2028 and U+2029)
  http://timelessrepo.com/json-isnt-a-javascript-subset
* Moved documentation from a git submodule to
  http://simplejson.readthedocs.org/

Version 2.1.6 released 2011-05-08

* Prevent segfaults with deeply nested JSON documents
  simplejson/simplejson#11
* Fix compatibility with Python 2.5
  simplejson/simplejson#5

Version 2.1.5 released 2011-04-17

* Built sdist tarball with setuptools_git installed. Argh.

Version 2.1.4 released 2011-04-17

* Does not try to build the extension when using PyPy
* Trailing whitespace after commas no longer emitted when indent is used
* Migrated to github http://github.com/simplejson/simplejson
15a9f54
@jsonn jsonn pushed a commit to jsonn/pkgsrc that referenced this pull request Oct 11, 2014
wiz Update to 2.2.1:
Version 2.2.1 released 2011-09-06

* Fix MANIFEST.in issue when building a sdist from a sdist.
  simplejson/simplejson#16

Version 2.2.0 released 2011-09-04

* Remove setuptools requirement, reverted to pure distutils
* use_decimal default for encoding (dump, dumps, JSONEncoder) is now True
* tuple encoding as JSON objects can be turned off with new
  tuple_as_array=False option.
  simplejson/simplejson#6
* namedtuple (or other tuple subclasses with _asdict methods) are now
  encoded as JSON objects rather than arrays by default. Can be disabled
  and treated as a tuple with the new namedtuple_as_object=False option.
  simplejson/simplejson#6
* JSONDecodeError is now raised instead of ValueError when a document
  ends with an opening quote and the C speedups are in use.
  simplejson/simplejson#15
* Updated documentation with information about JSONDecodeError
* Force unicode linebreak characters to be escaped (U+2028 and U+2029)
  http://timelessrepo.com/json-isnt-a-javascript-subset
* Moved documentation from a git submodule to
  http://simplejson.readthedocs.org/

Version 2.1.6 released 2011-05-08

* Prevent segfaults with deeply nested JSON documents
  simplejson/simplejson#11
* Fix compatibility with Python 2.5
  simplejson/simplejson#5

Version 2.1.5 released 2011-04-17

* Built sdist tarball with setuptools_git installed. Argh.

Version 2.1.4 released 2011-04-17

* Does not try to build the extension when using PyPy
* Trailing whitespace after commas no longer emitted when indent is used
* Migrated to github http://github.com/simplejson/simplejson
ad9e762
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.