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

Re: JSONPath

Expand Messages
  • Stefan Gössner
    ... One design criterion of the JSONPath syntax proposal is, that simple expressions are also valid in Javascript. That applies to these two expressions above.
    Message 1 of 4 , Sep 6, 2007
    • 0 Attachment
      > First, there is a choice of notation. It is simpler to select one and
      > stick to that.
      > And then the syntax is a bit more difficult than it should be.
      >
      > The first syntax:
      > $.store.book[0].title
      >
      > To end parsing a component you need to look for either a dot, an
      > opening square bracket or the end of line or the end of file
      >
      > The bracket notation is easier.
      > $['store']['book'][0]['title']
      >
      > To find the end of a component is easy, it ends with a single quote.
      > However there is another thing: after you have parsed an opening
      > bracket, you need to peek ahead at the following character to know if
      > it is a number or a string that follows.

      One design criterion of the JSONPath syntax proposal is, that simple
      expressions are also valid in Javascript. That applies to these two
      expressions above. Extensions to that were modelled on E4X and ES4.

      The parsing is not very expensive, when we use regular expressions.

      > Also, since json doesn't use single quotes but double quotes only, I
      > would use double quote to make it more similar. It might also make it
      > possible to reuse code in various json implementations.

      The idea to use JSONPath expressions inside of JSON structures
      intensively seems to favor the choice of single quotes. See

      { "expr": "$['store']['book'][0]['title']" }

      vs.

      { "expr": "$[\"store\"][\"book\"][0][\"title\"]" }

      as an example, where we need to escape all double quotes.

      > My idea is the following syntax.
      > $"store"."book"[0]."title"

      In fact this is also a valid JSONPath expression (with a dot after the
      '$' though), but unfortunately not a valid Javascript expression.

      As the JSONPath proposal is exactly that - a proposal, nothing is set
      in stone. Thanks for your feedback.
      --
      Stefan
    Your message has been successfully submitted and would be delivered to recipients shortly.