JSON

Discussion in 'Python' started by belred@gmail.com, Dec 6, 2007.

  1. Guest

    i tried a couple python json libraries. i used simplejson on the
    server and was using cjson on the client, but i ran into this issue.
    i'm now using simplejson on both sides, but i'm still interested in
    this issue. did i do something wrong? is there a bug in one of the
    libraries? or something i don't understand about the json spec?


    i problem is the line where i call cjson.decode() below:

    >>> import simplejson
    >>> import cjson
    >>>
    >>> sj = simplejson.dumps('http://server.com')
    >>> sj

    '"http:\\/\\/server.com"'
    >>> cj = cjson.encode('http://server.com')
    >>> cj

    '"http://server.com"'
    >>> simplejson.loads(cj)

    u'http://server.com'
    >>> cjson.decode(cj)

    'http://server.com'
    >>> simplejson.loads(sj)

    u'http://server.com'
    >>> cjson.decode(sj)

    'http:\\/\\/server.com' # is this correct????


    is that last statement really correct?

    thanks,

    bryan
     
    , Dec 6, 2007
    #1
    1. Advertising

  2. wrote:

    > i tried a couple python json libraries. i used simplejson on the
    > server and was using cjson on the client, but i ran into this issue.
    > i'm now using simplejson on both sides, but i'm still interested in
    > this issue. did i do something wrong? is there a bug in one of the
    > libraries? or something i don't understand about the json spec?
    >
    >
    > i problem is the line where i call cjson.decode() below:
    >
    >>>> import simplejson
    >>>> import cjson
    >>>>
    >>>> sj = simplejson.dumps('http://server.com')
    >>>> sj

    > '"http:\\/\\/server.com"'
    >>>> cj = cjson.encode('http://server.com')
    >>>> cj

    > '"http://server.com"'
    >>>> simplejson.loads(cj)

    > u'http://server.com'
    >>>> cjson.decode(cj)

    > 'http://server.com'
    >>>> simplejson.loads(sj)

    > u'http://server.com'
    >>>> cjson.decode(sj)

    > 'http:\\/\\/server.com' # is this correct????


    Known issue. See:
    http://blog.extracheese.org/2007/07/when-json-isnt-json.html

    Neither project has fixed it it seems. Not sure which is actually
    the "correct" way to do it, but it would be nice if they would agree.

    j
     
    Joshua Kugler, Dec 6, 2007
    #2
    1. Advertising

  3. Joshua Kugler <> wrote:
    > wrote:
    >
    >> i tried a couple python json libraries. i used simplejson on the
    >> server and was using cjson on the client, but i ran into this issue.
    >> i'm now using simplejson on both sides, but i'm still interested in
    >> this issue. did i do something wrong? is there a bug in one of the
    >> libraries? or something i don't understand about the json spec?
    >>
    >>
    >> i problem is the line where i call cjson.decode() below:
    >>
    >>>>> import simplejson
    >>>>> import cjson
    >>>>>
    >>>>> sj = simplejson.dumps('http://server.com')
    >>>>> sj

    >> '"http:\\/\\/server.com"'
    >>>>> cj = cjson.encode('http://server.com')
    >>>>> cj

    >> '"http://server.com"'
    >>>>> simplejson.loads(cj)

    >> u'http://server.com'
    >>>>> cjson.decode(cj)

    >> 'http://server.com'
    >>>>> simplejson.loads(sj)

    >> u'http://server.com'
    >>>>> cjson.decode(sj)

    >> 'http:\\/\\/server.com' # is this correct????

    >
    > Known issue. See:
    > http://blog.extracheese.org/2007/07/when-json-isnt-json.html
    >
    > Neither project has fixed it it seems. Not sure which is actually
    > the "correct" way to do it, but it would be nice if they would agree.


    Since both Opera and SpiderMonkey give http://server.com as result for
    eval('"http:\\/\\/server.com"'), I'd say cjson gets it wrong (If by
    nothing else than majority rule ;). That is unless I'm wrong that in
    javascript something like eval(JSON_repr_of_s) == s should be true.

    Marc
     
    Marc Christiansen, Dec 7, 2007
    #3
  4. Joshua Kugler <> wrote:
    >Known issue. See:
    >http://blog.extracheese.org/2007/07/when-json-isnt-json.html
    >
    >Neither project has fixed it it seems. Not sure which is actually
    >the "correct" way to do it, but it would be nice if they would agree.


    I think it's pretty clear (not just from that blog entry, but from
    the grammar at http://json.org/) that cjson is incorrectly decoding
    "\/". Whether it's sensible for simplejson to be encoding '/' as "\/"
    is up for grabs, but it's perfectly correct for it to do so, so one
    shouldn't expect it to be "fixed".

    --
    \S -- -- http://www.chaos.org.uk/~sion/
    "Frankly I have no feelings towards penguins one way or the other"
    -- Arthur C. Clarke
    her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump
     
    Sion Arrowsmith, Dec 7, 2007
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Florian Frank
    Replies:
    0
    Views:
    251
    Florian Frank
    Jun 30, 2009
  2. sajuptpm
    Replies:
    2
    Views:
    357
    sajuptpm
    Dec 28, 2012
  3. Acácio Centeno
    Replies:
    1
    Views:
    277
    dieter
    Feb 15, 2013
  4. Bryan Britten
    Replies:
    9
    Views:
    275
    Bryan Britten
    May 28, 2013
  5. David Karr
    Replies:
    1
    Views:
    177
    David Karr
    Jun 17, 2013
Loading...

Share This Page