Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #77505 > unrolled thread

Storing instances using jsonpickle

Started byJosh English <Joshua.R.English@gmail.com>
First post2014-09-03 13:32 -0700
Last post2014-09-06 14:27 -0400
Articles 3 on this page of 23 — 10 participants

Back to article view | Back to comp.lang.python


Contents

  Storing instances using jsonpickle Josh English <Joshua.R.English@gmail.com> - 2014-09-03 13:32 -0700
    Re: Storing instances using jsonpickle Ned Batchelder <ned@nedbatchelder.com> - 2014-09-03 16:52 -0400
      Re: Storing instances using jsonpickle Josh English <Joshua.R.English@gmail.com> - 2014-09-03 15:30 -0700
        Re: Storing instances using jsonpickle MRAB <python@mrabarnett.plus.com> - 2014-09-04 00:39 +0100
          Re: Storing instances using jsonpickle Denis McMahon <denismfmcmahon@gmail.com> - 2014-09-04 01:11 +0000
        Re: Storing instances using jsonpickle Ned Batchelder <ned@nedbatchelder.com> - 2014-09-03 22:18 -0400
          Re: Storing instances using jsonpickle Sam Raker <sam.raker@gmail.com> - 2014-09-03 21:52 -0700
          Re: Storing instances using jsonpickle Josh English <Joshua.R.English@gmail.com> - 2014-09-15 12:30 -0700
        Re: Storing instances using jsonpickle Chris Angelico <rosuav@gmail.com> - 2014-09-04 15:17 +1000
          Re: Storing instances using jsonpickle Dan Sommers <dan@tombstonezero.net> - 2014-09-05 04:38 +0000
            Re: Storing instances using jsonpickle Chris Angelico <rosuav@gmail.com> - 2014-09-05 15:08 +1000
        Re: Storing instances using jsonpickle MRAB <python@mrabarnett.plus.com> - 2014-09-04 12:07 +0100
        Re: Storing instances using jsonpickle MRAB <python@mrabarnett.plus.com> - 2014-09-05 18:04 +0100
          Re: Storing instances using jsonpickle Marko Rauhamaa <marko@pacujo.net> - 2014-09-05 20:16 +0300
            Re: Storing instances using jsonpickle Ned Batchelder <ned@nedbatchelder.com> - 2014-09-05 13:30 -0400
              Re: Storing instances using jsonpickle Marko Rauhamaa <marko@pacujo.net> - 2014-09-05 21:04 +0300
                Re: Storing instances using jsonpickle Ned Batchelder <ned@nedbatchelder.com> - 2014-09-05 16:50 -0400
                  Re: Storing instances using jsonpickle Marko Rauhamaa <marko@pacujo.net> - 2014-09-05 23:57 +0300
            Re: Storing instances using jsonpickle Irmen de Jong <irmen.NOSPAM@xs4all.nl> - 2014-09-06 00:18 +0200
        Re: Storing instances using jsonpickle Chris Angelico <rosuav@gmail.com> - 2014-09-06 10:20 +1000
        Re: Storing instances using jsonpickle MRAB <python@mrabarnett.plus.com> - 2014-09-06 17:32 +0100
        Re: Storing instances using jsonpickle Ned Batchelder <ned@nedbatchelder.com> - 2014-09-06 12:56 -0400
        Re: Storing instances using jsonpickle Terry Reedy <tjreedy@udel.edu> - 2014-09-06 14:27 -0400

Page 2 of 2 — ← Prev page 1 [2]


#77654

FromMRAB <python@mrabarnett.plus.com>
Date2014-09-06 17:32 +0100
Message-ID<mailman.13835.1410021129.18130.python-list@python.org>
In reply to#77511
On 2014-09-06 01:20, Chris Angelico wrote:
> On Sat, Sep 6, 2014 at 3:04 AM, MRAB <python@mrabarnett.plus.com>
> wrote:
>> JSON has 'true' and 'false'.
>>
>> Python has 'True' and 'False'.
>>
>> Therefore, if you want it to be able to drop it into Python's REPL,
>> it won't be compatible with JSON anyway! (Well, not unless you
>> define 'true' and 'false' first.)
>
> This is a new spec, so I guess the question is whether it's
> primarily "JSON with some more features" or "subset of Python syntax
> in the same way that JSON is a subset of JS". If it's the former,
> then yes, it'd use "true" and "false", and you'd have to define them;
> but if the latter, the spec would simply use "True" and "False". But
> being able to guarantee that JSON decodes correctly with this parser
> (ie make it a guaranteed superset of JSON) would be of value.
>
I've found that there's another issue with JSON: string escapes include
\u, but not \U:

 >>> json.dumps('\U0010FFFF')
'"\\udbff\\udfff"'

Yes, it uses surrogate escapes!

Also:

 >>> json.dumps('\uDBFF\uDFFF')
'"\\udbff\\udfff"'

so it won't round-trip.

On the other hand, you probably won't be using pairs of surrogate
escapes in Python 3.3+.

[toc] | [prev] | [next] | [standalone]


#77656

FromNed Batchelder <ned@nedbatchelder.com>
Date2014-09-06 12:56 -0400
Message-ID<mailman.13837.1410022605.18130.python-list@python.org>
In reply to#77511
On 9/6/14 12:32 PM, MRAB wrote:
> On 2014-09-06 01:20, Chris Angelico wrote:
>> On Sat, Sep 6, 2014 at 3:04 AM, MRAB <python@mrabarnett.plus.com>
>> wrote:
>>> JSON has 'true' and 'false'.
>>>
>>> Python has 'True' and 'False'.
>>>
>>> Therefore, if you want it to be able to drop it into Python's REPL,
>>> it won't be compatible with JSON anyway! (Well, not unless you
>>> define 'true' and 'false' first.)
>>
>> This is a new spec, so I guess the question is whether it's
>> primarily "JSON with some more features" or "subset of Python syntax
>> in the same way that JSON is a subset of JS". If it's the former,
>> then yes, it'd use "true" and "false", and you'd have to define them;
>> but if the latter, the spec would simply use "True" and "False". But
>> being able to guarantee that JSON decodes correctly with this parser
>> (ie make it a guaranteed superset of JSON) would be of value.
>>
> I've found that there's another issue with JSON: string escapes include
> \u, but not \U:
>
>  >>> json.dumps('\U0010FFFF')
> '"\\udbff\\udfff"'
>
> Yes, it uses surrogate escapes!
>
> Also:
>
>  >>> json.dumps('\uDBFF\uDFFF')
> '"\\udbff\\udfff"'
>
> so it won't round-trip.

Strings in JavaScript are explicitly defined to be sequences of 16-bit 
value, so the spec mandates surrogate pairs for codepoints outside the 
Basic Multilingual Plane, unfortunately.  JSON follows suit, also 
unfortunately.

>
> On the other hand, you probably won't be using pairs of surrogate
> escapes in Python 3.3+.


-- 
Ned Batchelder, http://nedbatchelder.com

[toc] | [prev] | [next] | [standalone]


#77662

FromTerry Reedy <tjreedy@udel.edu>
Date2014-09-06 14:27 -0400
Message-ID<mailman.13841.1410028089.18130.python-list@python.org>
In reply to#77511
On 9/6/2014 12:32 PM, MRAB wrote:
> On 2014-09-06 01:20, Chris Angelico wrote:
>> On Sat, Sep 6, 2014 at 3:04 AM, MRAB <python@mrabarnett.plus.com>
>> wrote:
>>> JSON has 'true' and 'false'.
>>>
>>> Python has 'True' and 'False'.
>>>
>>> Therefore, if you want it to be able to drop it into Python's REPL,
>>> it won't be compatible with JSON anyway! (Well, not unless you
>>> define 'true' and 'false' first.)
>>
>> This is a new spec, so I guess the question is whether it's
>> primarily "JSON with some more features" or "subset of Python syntax
>> in the same way that JSON is a subset of JS". If it's the former,
>> then yes, it'd use "true" and "false", and you'd have to define them;
>> but if the latter, the spec would simply use "True" and "False". But
>> being able to guarantee that JSON decodes correctly with this parser
>> (ie make it a guaranteed superset of JSON) would be of value.
>>
> I've found that there's another issue with JSON: string escapes include
> \u, but not \U:
>
>  >>> json.dumps('\U0010FFFF')
> '"\\udbff\\udfff"'
>
> Yes, it uses surrogate escapes!

Because Javascript does.  It does roundtrip properly (3.4.1)
 >>> json.loads('"\\udbff\\udfff"')
'\U0010ffff'

> Also:
>
>  >>> json.dumps('\uDBFF\uDFFF')
> '"\\udbff\\udfff"'
>
> so it won't round-trip.
>
> On the other hand, you probably won't be using pairs of surrogate
> escapes in Python 3.3.

The surrogate codepoints are not unicode characters and as I remember 
from reading the standard, would not be allowed in a strict utf-32 
implementation.  3.3+ uses them, when requested, to represent 
undecodable bytes in a non-standard fashion.
and for other occasional practical reasons that most of us can ignore.

-- 
Terry Jan Reedy

[toc] | [prev] | [standalone]


Page 2 of 2 — ← Prev page 1 [2]

Back to top | Article view | comp.lang.python


csiph-web