"Some String \xAE".to_json gives an illegal/malformed error?

Discussion in 'Ruby' started by Blackie, Oct 24, 2007.

  1. Blackie

    Blackie Guest

    Call me crazy, but I must be missing some fundamental understanding
    here.

    >From what I can read on the JSON gem located here (http://

    json.rubyforge.org/) this should be working but I'm getting a
    JSON::GeneratorError. Any insight you may have is appreciated.

    Given this:

    require 'json'
    => true

    s = ["MyStuff \xAE"]
    => ["MyStuff \256"]

    s.to_json
    JSON::GeneratorError: source sequence is illegal/malformed
    from (irb):16:in `to_json'
    from (irb):16

    Since that string has a unicode char in it, should it not be escape to
    \uXXXX when re convert to JSON?

    Any help is appreciated.
    Blackie, Oct 24, 2007
    #1
    1. Advertising

  2. Blackie

    Blackie Guest

    Never mind. Encoding on the DB is defaulting to latin-1. What I
    thought was unicode strings weren't. *Sigh* :)


    On Oct 24, 6:11 pm, Blackie <> wrote:
    > Call me crazy, but I must be missing some fundamental understanding
    > here.
    >
    > >From what I can read on the JSON gem located here (http://

    >
    > json.rubyforge.org/) this should be working but I'm getting a
    > JSON::GeneratorError. Any insight you may have is appreciated.
    >
    > Given this:
    >
    > require 'json'
    > => true
    >
    > s = ["MyStuff \xAE"]
    > => ["MyStuff \256"]
    >
    > s.to_json
    > JSON::GeneratorError: source sequence is illegal/malformed
    > from (irb):16:in `to_json'
    > from (irb):16
    >
    > Since that string has a unicode char in it, should it not be escape to
    > \uXXXX when re convert to JSON?
    >
    > Any help is appreciated.
    Blackie, Oct 25, 2007
    #2
    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. Replies:
    0
    Views:
    3,372
  2. Kiran B.

    Malformed header error... pls help!

    Kiran B., Nov 2, 2003, in forum: Python
    Replies:
    1
    Views:
    400
    Derrick 'dman' Hudson
    Nov 6, 2003
  3. Juan Pablo Romero Méndez

    What do you guys think about adding a method "to_json"

    Juan Pablo Romero Méndez, Sep 12, 2011, in forum: Python
    Replies:
    0
    Views:
    245
    Juan Pablo Romero Méndez
    Sep 12, 2011
  4. Fritz Trapper

    to_json / to_xml: where to find?

    Fritz Trapper, Sep 20, 2010, in forum: Ruby
    Replies:
    1
    Views:
    114
    Michael Fellinger
    Sep 20, 2010
  5. Replies:
    0
    Views:
    675
Loading...

Share This Page