Loading ...
Sorry, an error occurred while loading the content.

Re: [json] backslash double-quote

Expand Messages
  • Mark Miller
    ... Assuming your closing ) is an error, E s embedded term-tree language ( ) accepts this just fine: ?
    Message 1 of 13 , Aug 1, 2005
    • 0 Attachment
      jonschull5 wrote:
      > Hi,
      >
      > Shouldn't it be possible to jsonize a string like this?
      >
      > {"doubleQuoteSurroundedBySpaces":" \" "}}'


      Assuming your closing ")'" is an error, E's embedded term-tree language
      (<http://www.erights.org/data/terml/index.html>) accepts this just fine:

      ? term`{"doubleQuoteSurroundedBySpaces":" \" "}`
      # value: term`{"doubleQuoteSurroundedBySpaces": " \" "}`

      We altered E's term-tree language to be a superset of JSON. Shown above is a
      command-line interaction with the E interpreter. "? " is E's prompt. ("> " is
      E's continuation prompt, and is not shown here.) The text to the right of the
      "? " is an E expression entered by the user. The expression shown above is a
      quasi-literal expression, consisting of the name of the quasi-parser to the
      left of the back-tick, and the quasi-literal string to be parsed within the
      back-ticks. In this case we're just using it as a parser. To better see what's
      going on, below we invoke E's term-tree parser explicitly on your JSON string:

      ? def str := `{"doubleQuoteSurroundedBySpaces":" \" "}`
      # value: "{\"doubleQuoteSurroundedBySpaces\":\" \\\" \"}"

      ? def termParser := <import:org.quasiliteral.term.TermParser>
      # value: <makeTermParser>

      ? def tt := termParser(str)
      # value: term`{"doubleQuoteSurroundedBySpaces": " \" "}`

      We can use a quasi-literal pattern to pattern match this tree and extract its
      components. The text between the "@{" and "}" is a pattern in the E
      programming language. Whatever the term-tree quasi-literal pattern extracts at
      that position is matched against this E pattern, which in this case just
      coerces and binds variables k and v.

      Since both E and the term-tree language use ":", but for two quite different
      purposes, our convention is to put a space to the left of an E ":" but a space
      to the right of a term-tree colon.

      ? def term`{@{k :String}: @{v :String}}` := tt
      # value: term`{"doubleQuoteSurroundedBySpaces": " \" "}`

      ? k
      # value: "doubleQuoteSurroundedBySpaces"

      ? v
      # value: " \" "

      For more, see <http://www.erights.org/elang/quasi/terms/like-ellipses.html>
      and the section "Quasi-JSON back from the dead" at
      <http://www.eros-os.org/pipermail/e-lang/2005-May/010646.html>.

      --
      Text by me above is hereby placed in the public domain

      Cheers,
      --MarkM
    • Jon Schull
      Thanks for the speedy and extensive reply Yes, my closing ) was an error I m something of an E-gnoramus, so I will ask before attempting to understand your
      Message 2 of 13 , Aug 1, 2005
      • 0 Attachment
        Thanks for the speedy and extensive reply

        Yes, my closing ")" was an error

        I'm something of an E-gnoramus, so I will ask before attempting to
        understand your detailed reply, are there E-parsers available for
        python and javascript?


        =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
        Jon Schull, Ph.D.
        Associate Professor
        Information Technology
        Rochester Institute of Technology
        102 Lomb Memorial Drive
        Rochester, New York 14623
        schull@... 585-738-6696

        On Aug 1, 2005, at 5:04 PM, Mark Miller wrote:

        > jonschull5 wrote:
        > > Hi,
        > >
        > > Shouldn't it be possible to jsonize a string like this?
        > >
        > > {"doubleQuoteSurroundedBySpaces":" \" "}}'
        >
        >
        > Assuming your closing ")'" is an error, E's embedded term-tree
        > language
        > (<http://www.erights.org/data/terml/index.html>) accepts this just
        > fine:
        >
        > ? term`{"doubleQuoteSurroundedBySpaces":" \" "}`
        > # value: term`{"doubleQuoteSurroundedBySpaces": " \" "}`
        >
        > We altered E's term-tree language to be a superset of JSON. Shown
        > above is a
        > command-line interaction with the E interpreter. "? " is E's
        > prompt. ("> " is
        > E's continuation prompt, and is not shown here.) The text to the
        > right of the
        > "? " is an E expression entered by the user. The expression shown
        > above is a
        > quasi-literal expression, consisting of the name of the quasi-
        > parser to the
        > left of the back-tick, and the quasi-literal string to be parsed
        > within the
        > back-ticks. In this case we're just using it as a parser. To better
        > see what's
        > going on, below we invoke E's term-tree parser explicitly on your
        > JSON string:
        >
        > ? def str := `{"doubleQuoteSurroundedBySpaces":" \" "}`
        > # value: "{\"doubleQuoteSurroundedBySpaces\":\" \\\" \"}"
        >
        > ? def termParser := <import:org.quasiliteral.term.TermParser>
        > # value: <makeTermParser>
        >
        > ? def tt := termParser(str)
        > # value: term`{"doubleQuoteSurroundedBySpaces": " \" "}`
        >
        > We can use a quasi-literal pattern to pattern match this tree and
        > extract its
        > components. The text between the "@{" and "}" is a pattern in the E
        > programming language. Whatever the term-tree quasi-literal pattern
        > extracts at
        > that position is matched against this E pattern, which in this case
        > just
        > coerces and binds variables k and v.
        >
        > Since both E and the term-tree language use ":", but for two quite
        > different
        > purposes, our convention is to put a space to the left of an E ":"
        > but a space
        > to the right of a term-tree colon.
        >
        > ? def term`{@{k :String}: @{v :String}}` := tt
        > # value: term`{"doubleQuoteSurroundedBySpaces": " \" "}`
        >
        > ? k
        > # value: "doubleQuoteSurroundedBySpaces"
        >
        > ? v
        > # value: " \" "
        >
        > For more, see <http://www.erights.org/elang/quasi/terms/like-
        > ellipses.html>
        > and the section "Quasi-JSON back from the dead" at
        > <http://www.eros-os.org/pipermail/e-lang/2005-May/010646.html>.
        >
        > --
        > Text by me above is hereby placed in the public domain
        >
        > Cheers,
        > --MarkM
        >
        >
        > YAHOO! GROUPS LINKS
        >
        > Visit your group "json" on the web.
        >
        > To unsubscribe from this group, send an email to:
        > json-unsubscribe@yahoogroups.com
        >
        > Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.
        >
        >



        [Non-text portions of this message have been removed]
      • Mark Miller
        ... Unfortunately no. Currently, E runs only on the JVM. There are ports of E onto Common Lisp and Squeak in progress, but neither is ready yet. Porting E onto
        Message 3 of 13 , Aug 1, 2005
        • 0 Attachment
          Jon Schull wrote:
          > Thanks for the speedy and extensive reply
          >
          > Yes, my closing ")" was an error
          >
          > I'm something of an E-gnoramus, so I will ask before attempting to
          > understand your detailed reply, are there E-parsers available for
          > python and javascript?


          Unfortunately no. Currently, E runs only on the JVM. There are ports of E onto
          Common Lisp and Squeak in progress, but neither is ready yet.

          Porting E onto Python or Javascript would be a major effort. However, I
          suspect that E's quasi-literal framework and its term-tree system as an
          instance of that framework could easily be reimplemented in Python.

          --
          Text by me above is hereby placed in the public domain

          Cheers,
          --MarkM
        • jonschull5
          I don t understand why this isn t considered a serious flaw in JSON... For any object o, it should be true that json.read( json.write(o) ) == o But this is not
          Message 4 of 13 , Aug 2, 2005
          • 0 Attachment
            I don't understand why this isn't considered a serious flaw in JSON...

            For any object o, it should be true that

            json.read( json.write(o) ) == o

            But this is not true for the object {'a':' " '}

            ???????????

            A similarly fatal problem arises when I try to jsonize some a DOM
            element that includes an onclick method with a quoted argument. This
            is not an improbable use case.

            Is there no solution?
          • jonschull5
            P.S. I ve determined that Crockford s javascript parser does not have this problem (which I found in patrick logan s json.py). With javascript, o2= son.parse(
            Message 5 of 13 , Aug 2, 2005
            • 0 Attachment
              P.S. I've determined that Crockford's javascript parser does not have
              this problem (which I found in patrick logan's json.py).

              With javascript,

              o2= son.parse( json.stringify(o) )
              o2.a == o.a is TRUE
              and o2.toSource()==o.ToSource() is also TRUE


              (interestingly...
              json.parse( json.stringify(o) ) == o fails
              but that's another story, I think )

              --- In json@yahoogroups.com, "jonschull5" <schull@d...> wrote:
              > I don't understand why this isn't considered a serious flaw in JSON...
              >
              > For any object o, it should be true that
              >
              > json.read( json.write(o) ) == o
              >
              > But this is not true for the object {'a':' " '}
              >
              > ???????????
              >
              > A similarly fatal problem arises when I try to jsonize some a DOM
              > element that includes an onclick method with a quoted argument. This
              > is not an improbable use case.
              >
              > Is there no solution?
            • Martin Cooper
              ... I m not sure which implementation you re referring to, since JSON is just a spec, but I m surprised the above even parses as valid JSON. Strings in JSON
              Message 6 of 13 , Aug 2, 2005
              • 0 Attachment
                On 8/2/05, jonschull5 <schull@...> wrote:
                > I don't understand why this isn't considered a serious flaw in JSON...
                >
                > For any object o, it should be true that
                >
                > json.read( json.write(o) ) == o
                >
                > But this is not true for the object {'a':' " '}

                I'm not sure which implementation you're referring to, since JSON is
                just a spec, but I'm surprised the above even parses as valid JSON.
                Strings in JSON must be surrounded by double quotes, and single quotes
                are not valid.

                --
                Martin Cooper


                > ???????????
                >
                > A similarly fatal problem arises when I try to jsonize some a DOM
                > element that includes an onclick method with a quoted argument. This
                > is not an improbable use case.
                >
                > Is there no solution?
                >
                >
                >
                >
                >
                >
                >
                >
                > Yahoo! Groups Links
                >
                >
                >
                >
                >
                >
                >
              • Jon Schull
                Ok, I should have said a serious flaw in the json.py library And it turns out to be a problem in the two python libraries I ve looked at
                Message 7 of 13 , Aug 2, 2005
                • 0 Attachment
                  Ok, I should have said "a serious flaw in the json.py library"

                  And it turns out to be a problem in the two python libraries I've
                  looked at
                  (https://sourceforge.net/projects/json-py/ and http://python.ca/nas/
                  log/)

                  I'm surprised the requirement that strings be surrounded by double
                  quotes applies to the objects themselves. I don't think we can
                  always control the quoting of nested expressions....


                  =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
                  Jon Schull, Ph.D.
                  Associate Professor
                  Information Technology
                  Rochester Institute of Technology
                  102 Lomb Memorial Drive
                  Rochester, New York 14623
                  schull@... 585-738-6696

                  On Aug 3, 2005, at 12:35 AM, Martin Cooper wrote:

                  > On 8/2/05, jonschull5 <schull@...> wrote:
                  > > I don't understand why this isn't considered a serious flaw in
                  > JSON...
                  > >
                  > > For any object o, it should be true that
                  > >
                  > > json.read( json.write(o) ) == o
                  > >
                  > > But this is not true for the object {'a':' " '}
                  >
                  > I'm not sure which implementation you're referring to, since JSON is
                  > just a spec, but I'm surprised the above even parses as valid JSON.
                  > Strings in JSON must be surrounded by double quotes, and single quotes
                  > are not valid.
                  >
                  > --
                  > Martin Cooper
                  >
                  >
                  > > ???????????
                  > >
                  > > A similarly fatal problem arises when I try to jsonize some a DOM
                  > > element that includes an onclick method with a quoted argument.
                  > This
                  > > is not an improbable use case.
                  > >
                  > > Is there no solution?
                  > >
                  > >
                  > >
                  > >
                  > >
                  > >
                  > >
                  > >
                  > > Yahoo! Groups Links
                  > >
                  > >
                  > >
                  > >
                  > >
                  > >
                  > >
                  >
                  >
                  > SPONSORED LINKS
                  > Json Programming languages Format
                  > Computer security Computer training Large format
                  >
                  > YAHOO! GROUPS LINKS
                  >
                  > Visit your group "json" on the web.
                  >
                  > To unsubscribe from this group, send an email to:
                  > json-unsubscribe@yahoogroups.com
                  >
                  > Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.
                  >
                  >



                  [Non-text portions of this message have been removed]
                • Michal Migurski
                  ... The json.py library definitely has some problems. I ve found a few flaws in the way it encodes strings, which I ve sent back to Patrick as patches. I m
                  Message 8 of 13 , Aug 2, 2005
                  • 0 Attachment
                    > Ok, I should have said "a serious flaw in the json.py library"

                    The json.py library definitely has some problems. I've found a few
                    flaws in the way it encodes strings, which I've sent back to Patrick
                    as patches. I'm only using write() method.

                    -mike.

                    ------------------------------------------------------
                    michal migurski- contact info, blog, and pgp key:
                    sf/ca http://mike.teczno.com/contact.html
                  • Mark Miller
                    ... In E, this gives a syntax error as it should: ? term`{ a : }` # syntax error: # { a : } # ^ -- Text by me above is hereby placed in
                    Message 9 of 13 , Aug 2, 2005
                    • 0 Attachment
                      jonschull5 wrote:
                      > I don't understand why this isn't considered a serious flaw in JSON...
                      >
                      > For any object o, it should be true that
                      >
                      > json.read( json.write(o) ) == o
                      >
                      > But this is not true for the object {'a':' " '}

                      In E, this gives a syntax error as it should:

                      ? term`{'a':' " '}`
                      # syntax error:
                      # {'a':' " '}
                      # ^

                      --
                      Text by me above is hereby placed in the public domain

                      Cheers,
                      --MarkM
                    • jemptymethod
                      Since it s Python, an option might be to access Mr Crockford s Java implementation of JSON, via Jython.
                      Message 10 of 13 , Aug 3, 2005
                      • 0 Attachment
                        Since it's Python, an option might be to access Mr Crockford's Java
                        implementation of JSON, via Jython.

                        --- In json@yahoogroups.com, Michal Migurski <mike-jsonphp@t...> wrote:
                        > > Ok, I should have said "a serious flaw in the json.py library"
                        >
                        > The json.py library definitely has some problems. I've found a few
                        > flaws in the way it encodes strings, which I've sent back to Patrick
                        > as patches. I'm only using write() method.
                        >
                        > -mike.
                        >
                        > ------------------------------------------------------
                        > michal migurski- contact info, blog, and pgp key:
                        > sf/ca http://mike.teczno.com/contact.html
                      • Patrick D. Logan
                        oops. Editing error from the Python interpreter. The resulting json representation should look something like... { a : } -Patrick [Non-text portions of
                        Message 11 of 13 , Aug 3, 2005
                        • 0 Attachment
                          oops. Editing error from the Python interpreter. The resulting json representation should look something like...

                          {"a":" \" "}

                          -Patrick


                          [Non-text portions of this message have been removed]
                        • jonschull5
                          Just thought I d put it on record that both Patrick Logan and Neil Schemenauer promptly fixed and updated their python json libraries. Logan:
                          Message 12 of 13 , Aug 6, 2005
                          • 0 Attachment
                            Just thought I'd put it on record that both Patrick Logan and Neil
                            Schemenauer promptly fixed and updated their python json libraries.
                            Logan: https://sourceforge.net/projects/json-py/
                            Schemenauer: http://arctrix.com/nas/python/json-1.1.tar.gz

                            While they have slightly different output formats (Neil's is more
                            verbose, but more human-readable) they seem to be interoperable with
                            each other and with Crockford's javascript library (which is as it
                            should be).

                            Thanks to all!

                            Jon
                            http://jonschull.blogspot.com
                          Your message has been successfully submitted and would be delivered to recipients shortly.