Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
parts of the REST API are not valid JSON
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  20 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Max De Marzi Jr.  
View profile  
 More options Dec 31 2011, 11:44 am
From: "Max De Marzi Jr." <maxdema...@gmail.com>
Date: Sat, 31 Dec 2011 08:44:43 -0800 (PST)
Local: Sat, Dec 31 2011 11:44 am
Subject: parts of the REST API are not valid JSON
Ran into an ugly problem today.

In neography, I use the httparty gem which switched from crack to
multijson for json parsing.
Turns out multijson is strict and doesn't like some of the things the
neo4j rest api is returning:

For example:
http://docs.neo4j.org/chunked/snapshot/rest-api-relationships.html#re...

Example request

PUT http://localhost:7474/db/data/relationship/13/properties/cost
Accept: application/json
Content-Type: application/json
"deadly"

"deadly" is not valid json.  It's valid  'text/plain'.
{"cost":"deadly"} would valid json.

You guys can change the content-type or the returned value, or I can
code a workaround... but others writing rest clients may run into this
issue too.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jim Webber  
View profile  
 More options Dec 31 2011, 11:48 am
From: Jim Webber <j...@neotechnology.com>
Date: Sat, 31 Dec 2011 16:48:43 +0000
Local: Sat, Dec 31 2011 11:48 am
Subject: Re: [Neo4j] parts of the REST API are not valid JSON
Hi Max,

If you raise an issue against this, we'll get onto it. I like the idea of fixing it at source rather than having many workarounds in all the client libraries.

Jim

On 31 Dec 2011, at 16:44, Max De Marzi Jr. wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Hendy Irawan  
View profile  
 More options Dec 31 2011, 11:49 am
From: Hendy Irawan <ceefour...@gmail.com>
Date: Sat, 31 Dec 2011 23:49:09 +0700
Local: Sat, Dec 31 2011 11:49 am
Subject: Re: [Neo4j] parts of the REST API are not valid JSON

Indeed Max is correct.

JSON root must be either an object or an array.

["deadly"] also works and the overhead is minimal (2 characters)

On Sat, Dec 31, 2011 at 11:44 PM, Max De Marzi Jr. <maxdema...@gmail.com>wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Max De Marzi Jr.  
View profile  
 More options Dec 31 2011, 11:54 am
From: "Max De Marzi Jr." <maxdema...@gmail.com>
Date: Sat, 31 Dec 2011 08:54:12 -0800 (PST)
Local: Sat, Dec 31 2011 11:54 am
Subject: Re: parts of the REST API are not valid JSON
I made a bad copy and paste job. What I mean is that getting a single
node property does not return valid JSON.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Max De Marzi Jr.  
View profile  
 More options Dec 31 2011, 12:01 pm
From: "Max De Marzi Jr." <maxdema...@gmail.com>
Date: Sat, 31 Dec 2011 09:01:02 -0800 (PST)
Local: Sat, Dec 31 2011 12:01 pm
Subject: Re: parts of the REST API are not valid JSON
 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
James Thornton  
View profile  
 More options Dec 31 2011, 12:25 pm
From: James Thornton <james.thorn...@gmail.com>
Date: Sat, 31 Dec 2011 09:25:32 -0800 (PST)
Local: Sat, Dec 31 2011 12:25 pm
Subject: Re: parts of the REST API are not valid JSON

This issue is also mentioned here:
https://github.com/neo4j/community/issues/119

- James


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Alistair Jones  
View profile  
 More options Dec 31 2011, 1:37 pm
From: Alistair Jones <alistair.jo...@neotechnology.com>
Date: Sat, 31 Dec 2011 10:37:19 -0800 (PST)
Local: Sat, Dec 31 2011 1:37 pm
Subject: Re: parts of the REST API are not valid JSON
I'm happy to be corrected, but this is surprising to me.  I've read
the page at http://json.org/ and I don't see anything that says object
and array are the only allowed parsing goals. In Chrome, I can do
JSON.parse("\"Hello\"") without error, and it appears to work for all
value types.  I've just tried using Douglas Crockford's reference
parser implementation from here:
https://github.com/douglascrockford/JSON-js/blob/master/json_parse.js
This also allows values as valid JSON.

However, I can find other places where values are not considered valid
JSON, such as here:
http://json.parser.online.fr/
Clearly multijson is also in this camp.

Where can I find a standard which says that only objects and arrays
are allowed?

-Alistair

On Dec 31, 4:44 pm, "Max De Marzi Jr." <maxdema...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Tero Paananen  
View profile  
 More options Dec 31 2011, 1:50 pm
From: Tero Paananen <teropaana...@gmail.com>
Date: Sat, 31 Dec 2011 13:50:30 -0500
Local: Sat, Dec 31 2011 1:50 pm
Subject: Re: [Neo4j] Re: parts of the REST API are not valid JSON

> Where can I find a standard which says that only objects and arrays
> are allowed?

I'm not sure about this, but I'm going to comment on the structure of
the JSON package from a developer's perspective.

To me, it would always be better, if the JSON packages were "fully formed".

{ "propertyName" : "propertyValue" }

is inherently better to deal with than:

"propertyValue"

Two reasons that come quickly to my mind:

1. I can parse the response of this query with the same code that parses
    responses for multiple properties, e.g. { "foo" : "bar", "yo" : "momma" }

2. Parsing the response isn't coupled to the request. In the latter version
    the parsing code needs to know that I requested a particular property value.

-TPP


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Max De Marzi Jr.  
View profile  
 More options Dec 31 2011, 4:56 pm
From: "Max De Marzi Jr." <maxdema...@gmail.com>
Date: Sat, 31 Dec 2011 13:56:09 -0800 (PST)
Local: Sat, Dec 31 2011 4:56 pm
Subject: Re: parts of the REST API are not valid JSON
Alistair, I think the spec you want is http://www.ietf.org/rfc/rfc4627
, specifically:

2.  JSON Grammar

   A JSON text is a sequence of tokens.  The set of tokens includes
six
   structural characters, strings, numbers, and three literal names.

   A JSON text is a serialized object or array.

      JSON-text = object / array"


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Josh Adell  
View profile  
 More options Dec 31 2011, 5:33 pm
From: Josh Adell <josh.ad...@gmail.com>
Date: Sat, 31 Dec 2011 14:33:39 -0800 (PST)
Local: Sat, Dec 31 2011 5:33 pm
Subject: Re: parts of the REST API are not valid JSON
Except that section 1 of http://www.ietf.org/rfc/rfc4627 seems to read
that valid JSON can be a simple scalar value:

1. Introduction
...
   JSON can represent four primitive types (strings, numbers,
booleans,
   and null) and two structured types (objects and arrays).
...

FWIW, the PHP built-in json_encode function treats scalars as valid
JSON.

-- Josh Adell

On Dec 31, 4:56 pm, "Max De Marzi Jr." <maxdema...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Josh Adell  
View profile  
 More options Dec 31 2011, 6:33 pm
From: Josh Adell <josh.ad...@gmail.com>
Date: Sat, 31 Dec 2011 15:33:59 -0800 (PST)
Local: Sat, Dec 31 2011 6:33 pm
Subject: Re: parts of the REST API are not valid JSON
I just talked with one of the development leads for jQuery UI (not an
authoritative source, I know) and he says that scalar values are valid
JSON.

I also checked out ECMA-262, which defines how JSON is parsed in
Javascript, and it explicitly lists differences between Javascript's
JSON.parse/.stringify and RFC 4627.
http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262...
at the bottom of page 201.

tl;dr: The RFC says the top level must be an object or array. ECMA
says it can be any valid JSON value (object, array or scalar).

So it seems that it depends on if you think ECMA or the RFC is the
standard, which probably accounts for why different libraries and
languages implement it differently.

My final thought on this is a memory of something a Javascript
developer told me about implementation differences between Javascript
parsers: "When in doubt, do what Crockford says."

Happy New Year, all!

-- Josh

On Dec 31, 5:33 pm, Josh Adell <josh.ad...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Peter Neubauer  
View profile  
 More options Dec 31 2011, 7:22 pm
From: Peter Neubauer <neubauer.pe...@gmail.com>
Date: Sun, 1 Jan 2012 01:22:57 +0100
Local: Sat, Dec 31 2011 7:22 pm
Subject: Re: [Neo4j] Re: parts of the REST API are not valid JSON

Sounds to me that a change away from scalars would satisfy everyone and be
least friction.next issue is good versioning of the rest API.

Cheers

/peter

Sent from a device with crappy keyboard and autocorrect
On Jan 1, 2012 12:34 AM, "Josh Adell" <josh.ad...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Alistair Jones  
View profile  
 More options Jan 1 2012, 8:51 am
From: Alistair Jones <alistair.jo...@neotechnology.com>
Date: Sun, 1 Jan 2012 13:51:46 +0000
Local: Sun, Jan 1 2012 8:51 am
Subject: Re: [Neo4j] Re: parts of the REST API are not valid JSON

On 31 December 2011 21:56, Max De Marzi Jr. <maxdema...@gmail.com> wrote:

> Alistair, I think the spec you want is http://www.ietf.org/rfc/rfc4627
> , specifically:

> 2.  JSON Grammar

>   A JSON text is a sequence of tokens.  The set of tokens includes
> six
>   structural characters, strings, numbers, and three literal names.

>   A JSON text is a serialized object or array.

>      JSON-text = object / array"

Thanks Max, that's exactly what I was looking for - seems very clear.  My
fault for looking at implementations rather than the spec.

cheers,

-Alistair


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Alistair Jones  
View profile  
 More options Jan 1 2012, 9:11 am
From: Alistair Jones <alistair.jo...@neotechnology.com>
Date: Sun, 1 Jan 2012 14:11:43 +0000
Local: Sun, Jan 1 2012 9:11 am
Subject: Re: [Neo4j] Re: parts of the REST API are not valid JSON

On 31 December 2011 23:33, Josh Adell <josh.ad...@gmail.com> wrote:

> I just talked with one of the development leads for jQuery UI (not an
> authoritative source, I know) and he says that scalar values are valid
> JSON.

> I also checked out ECMA-262, which defines how JSON is parsed in
> Javascript, and it explicitly lists differences between Javascript's
> JSON.parse/.stringify and RFC 4627.
> http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262...
> at the bottom of page 201.

This makes it all clear now - thank you.

> tl;dr: The RFC says the top level must be an object or array. ECMA
> says it can be any valid JSON value (object, array or scalar).

> So it seems that it depends on if you think ECMA or the RFC is the
> standard, which probably accounts for why different libraries and
> languages implement it differently.

I think our starting point is that we advertise application/json mime type,
and IANA refers to
RFC4627<http://www.iana.org/assignments/media-types/application/index.html>,
so that's what we should really conform to, not the behaviour of any JSON
parser, such as the one defined by ECMAScript.

> My final thought on this is a memory of something a Javascript
> developer told me about implementation differences between Javascript
> parsers: "When in doubt, do what Crockford says."

That's what I thought too :-)

> Happy New Year, all!

Happy New Year!

-Alistair


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Alistair Jones  
View profile  
 More options Jan 1 2012, 9:13 am
From: Alistair Jones <alistair.jo...@neotechnology.com>
Date: Sun, 1 Jan 2012 14:13:11 +0000
Local: Sun, Jan 1 2012 9:13 am
Subject: Re: [Neo4j] Re: parts of the REST API are not valid JSON

On 1 January 2012 00:22, Peter Neubauer <neubauer.pe...@gmail.com> wrote:

> Sounds to me that a change away from scalars would satisfy everyone and be
> least friction.next issue is good versioning of the rest API.

Yes, I agree now.  Sorry for the noise.

-Alistair


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jacob Hansson  
View profile  
 More options Jan 2 2012, 6:48 am
From: Jacob Hansson <jacob.hans...@neotechnology.com>
Date: Mon, 2 Jan 2012 12:48:50 +0100
Local: Mon, Jan 2 2012 6:48 am
Subject: Re: [Neo4j] Re: parts of the REST API are not valid JSON

On Sun, Jan 1, 2012 at 3:13 PM, Alistair Jones <

alistair.jo...@neotechnology.com> wrote:
> On 1 January 2012 00:22, Peter Neubauer <neubauer.pe...@gmail.com> wrote:

>> Sounds to me that a change away from scalars would satisfy everyone and
>> be least friction.next issue is good versioning of the rest API.

> Yes, I agree now.  Sorry for the noise.

This has been discussed before, and we decided against making this change.

I'm against it, for two reasons. One, it will break all current client
implementations, and two, the solution using a json object is inelegant and
will potentially cause confusion.

The argument that it breaks the spec is invalid, because the spec is, like
Josh says, unclear on the subject. All JSON parsers I have ever used (among
others, parsers in java, php, python, javascript, c and ruby) opt for
following ECMA, rather than RFC.

The argument that the current solution forces me to write code that
remembers what property it is fetching is true, but the exact same argument
could be made for the object-based solution (the code needs to remember
what node it is fetching the property from, and what database, and what
server, ad infinitum), so I don't see how it's relevant. On the contrary,
not remembering what property you are fetching means you have to iterate
through the returned map to find the property key, as well as adding checks
to make sure there is really only one property in the map and so on.

The only real argument for making the change is that there could be JSON
parsers that do not support ECMA properly. So far multijson is the *only*
parser we have encountered that does not implement ECMA JSON correctly.

So the actual decision is between these two options: break all current
clients and introduce a less elegant API that is harder to use, or asking
developers to not use this one uncompliant JSON parser.

/jake

> -Alistair

--
Jacob Hansson
Phone: +46 (0) 763503395
Twitter: @jakewins

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jacob Hansson  
View profile  
 More options Jan 5 2012, 8:05 am
From: Jacob Hansson <jacob.hans...@neotechnology.com>
Date: Thu, 5 Jan 2012 14:05:35 +0100
Local: Thurs, Jan 5 2012 8:05 am
Subject: Re: [Neo4j] Re: parts of the REST API are not valid JSON

On Mon, Jan 2, 2012 at 12:48 PM, Jacob Hansson <

Does anybody disagree, or can I close the issue?

jake

>> -Alistair

> --
> Jacob Hansson
> Phone: +46 (0) 763503395
> Twitter: @jakewins

--
Jacob Hansson
Phone: +46 (0) 763503395
Twitter: @jakewins

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Peter Neubauer  
View profile  
 More options Jan 5 2012, 8:17 am
From: Peter Neubauer <peter.neuba...@neotechnology.com>
Date: Thu, 5 Jan 2012 14:17:31 +0100
Local: Thurs, Jan 5 2012 8:17 am
Subject: Re: [Neo4j] Re: parts of the REST API are not valid JSON
ok,
please close it. Max, ok?

Cheers,

/peter neubauer

Google:    neubauer.peter
Skype:     peter.neubauer
Phone:     +46 704 106975
LinkedIn:  http://www.linkedin.com/in/neubauer
Twitter:    @peterneubauer
Tungle:    tungle.me/peterneubauer

brew install neo4j && neo4j start
heroku addons:add neo4j

On Thu, Jan 5, 2012 at 2:05 PM, Jacob Hansson


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Max De Marzi Jr.  
View profile  
 More options Jan 5 2012, 10:15 am
From: "Max De Marzi Jr." <maxdema...@gmail.com>
Date: Thu, 5 Jan 2012 07:15:06 -0800 (PST)
Local: Thurs, Jan 5 2012 10:15 am
Subject: Re: parts of the REST API are not valid JSON
That's fine.
David Pitman sent me a pull request with a workaround this issue.

https://github.com/maxdemarzi/neography/pull/22

On Jan 5, 7:17 am, Peter Neubauer <peter.neuba...@neotechnology.com>
wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
James Thornton  
View profile  
 More options Jan 5 2012, 10:18 am
From: James Thornton <james.thorn...@gmail.com>
Date: Thu, 5 Jan 2012 07:18:31 -0800 (PST)
Local: Thurs, Jan 5 2012 10:18 am
Subject: Re: [Neo4j] Re: parts of the REST API are not valid JSON

On Thursday, January 5, 2012 7:05:35 AM UTC-6, Jacob Hansson wrote:

Does anybody disagree, or can I close the issue?


Another issue is that clients have to maintain a slew of conditionals in
the low-level serialization code to handle the different cases -- this is a
hotspot for bugs. esp in a growing API.

Ideally return data would always be in "data" and error messages would
always be in a standard place.

As it is right now, return data is usually in "data" but sometimes it's
not. Sometimes just "null" is returned. Sometimes no data is returned (e.g.
on updates). And error messages are not returned as JSON.

Consistency is key to avoiding exploding conditionals.

- James


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »