Problem loading embedded document with fromJSON


#1

I have the following peace of code:
ODocument doc = session.newInstance(); // Where session is a previously created valid ODatabaseSession
doc.fromJSON(str);

The str is a valid JSON array (for example [“abc”, “def”, “ghi”].
I’m getting an exception "OSerializationException: Error on unmarshalling JSON content … : content must be between { }. The way I see it a JSON array is a valid JSON (and all the other databases accept it as JSON), why do I need to create a dummy entry in the string so that it looks like a JSON object - e.g. {“dummy”:[“abc”, “def”, “ghi”]}.


#2

Hi,
could you post the json code?

Thanks
Regards,
Michela


#3

As I explained in the original post I’m trying to set a document to a JSON array. The JSON array starts with [ rather than the expected JSON object which starts with {.
So:
ODocument doc = session.newInstance();
doc.fromJSON("{“dummy”:[1,2,3]}");
works but
ODocument doc = session.newInstance();
doc.fromJSON("[1,2,3]");
doesn’t although a JSON array is a valid JSON.


#4

You need to keep a name for the json array, which is missing.


#5

I know that. If I create a JSON object as {“name”: JSON array} it works, but my point was that a JSON array in itself is a valid JSON that is not required to be wrapped in a JSON object