Rest API doesn't support empty arrays

45 views
Skip to first unread message

Red

unread,
Oct 16, 2016, 7:14:22 PM10/16/16
to Neo4j

CREATE (root {name: "foobar", cars: []}) RETURN root


Queries, like above are impossible through rest

https://github.com/philippkueng/node-neo4j/issues/12
https://github.com/versae/neo4j-rest-client/issues/130

Isn't it a bug?

Alan Robertson

unread,
Oct 19, 2016, 2:49:34 PM10/19/16
to ne...@googlegroups.com
In their data typing system, they need to know the type of the array elements.

For example: Is it an array of strings, or ints, or floats?

There is no "array of to-be-determined"...

So, they don't consider it a bug...

In my case either I don't set that attribute to a value when I create the object, or I set it to a single empty string as the value - like [""] and my code understands what this means.

It definitely makes you have to work harder...

    -- Alan
--
You received this message because you are subscribed to the Google Groups "Neo4j" group.
To unsubscribe from this group and stop receiving emails from it, send an email to neo4j+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Clark Richey

unread,
Oct 19, 2016, 4:02:21 PM10/19/16
to ne...@googlegroups.com
Maybe I'm missing something but why do you want to store an empty array as a property? An empty array is logically equivalent to null. Null is logically equivalent to not storing a value for hat property. Not storing a value for a property is more efficient than writing value = null to disk. 

So, shouldn't you just not store a cars property in your example?

Sent from my iPhone

Nigel Small

unread,
Oct 19, 2016, 5:38:50 PM10/19/16
to Neo4j
Hi

As Alan mentions, this is a side-effect of both Neo4j's type system and the JSON format used by the HTTP server. The type system at store level has no concept of an untyped array and JSON has no way to transmit type information independent of value, so it's impossible for the server to determine what type the received array should be stored as. Clark's suggestion of using a null would be typically used here; your application can then choose to interpret a null/missing property as an empty list.

Nigel

On 19 October 2016 at 21:02, Clark Richey <clark....@gmail.com> wrote:
Maybe I'm missing something but why do you want to store an empty array as a property? An empty array is logically equivalent to null. Null is logically equivalent to not storing a value for hat property. Not storing a value for a property is more efficient than writing value = null to disk. 

So, shouldn't you just not store a cars property in your example?

Sent from my iPhone

On Oct 19, 2016, at 14:49, Alan Robertson <al...@unix.sh> wrote:

In their data typing system, they need to know the type of the array elements.

For example: Is it an array of strings, or ints, or floats?

There is no "array of to-be-determined"...

So, they don't consider it a bug...

In my case either I don't set that attribute to a value when I create the object, or I set it to a single empty string as the value - like [""] and my code understands what this means.

It definitely makes you have to work harder...

    -- Alan


On 10/10/2016 01:02 AM, Red wrote:

CREATE (root {name: "foobar", cars: []}) RETURN root


Queries, like above are impossible through rest

https://github.com/philippkueng/node-neo4j/issues/12
https://github.com/versae/neo4j-rest-client/issues/130

Isn't it a bug?
--
You received this message because you are subscribed to the Google Groups "Neo4j" group.
To unsubscribe from this group and stop receiving emails from it, send an email to neo4j+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google Groups "Neo4j" group.
To unsubscribe from this group and stop receiving emails from it, send an email to neo4j+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Neo4j" group.
To unsubscribe from this group and stop receiving emails from it, send an email to neo4j+unsubscribe@googlegroups.com.

Alan Robertson

unread,
Oct 20, 2016, 12:39:28 PM10/20/16
to ne...@googlegroups.com
On 10/19/2016 03:38 PM, 'Nigel Small' via Neo4j wrote:
Hi

As Alan mentions, this is a side-effect of both Neo4j's type system and the JSON format used by the HTTP server. The type system at store level has no concept of an untyped array and JSON has no way to transmit type information independent of value, so it's impossible for the server to determine what type the received array should be stored as. Clark's suggestion of using a null would be typically used here; your application can then choose to interpret a null/missing property as an empty list.

To elaborate a little further on what Nigel said...
JSON doesn't restrict arrays to requiring all elements to be of the same type, but Neo4j's relatively strongly-typed type system (based on Java) does make this requirement.

For example, this is a perfectly legitimate JSON array value:
    [true, 1.0, 3, null, "fred", {"a": "b"}]

This is also legal in Python - but Neo4j doesn't support values like this at all.

To be fair, the last value (a hash table) isn't allowed anywhere in Neo4j. But even if you leave it out, the rest of the array elements can't be mixed either.

JSON supports lots of values which can't be stored by Neo4j - but your example seems common to me.

And to be fair to the original questioner: It is semantically different to say that a value doesn't exist than it to say that it does exist and is an empty array. Often you don't care about the difference, but sometimes you do.

Myself, I would love for Neo4j to support full JSON value power and flexibility - but it doesn't. That's life.

For my two cents worth - allowing hash tables (JSON objects) as values is far more interesting to me than empty arrays. I can fake up something for empty arrays (like the solution Nigel suggested), but not for JSON objects.

    -- Alan




To unsubscribe from this group and stop receiving emails from it, send an email to neo4j+un...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages