arangoclient.net icon indicating copy to clipboard operation
arangoclient.net copied to clipboard

IDocumentCollection.Collection returns invalid JSON when using JObject as a type

Open adamlubek opened this issue 8 years ago • 7 comments

Hi, I have following content stored in a collection: arango

Then, I do

db.Collection(Rule.RULES_COLLECTION_NAME) .All<JObject>() .ToList()

(JObject comes from ArangoDB.Client.Common.Newtonsoft.Json.Linq)

which returns: code

which is not a valid JSON (see double curly braces surrounding each object). Am I missing something or is this a bug?

adamlubek avatar May 04 '16 14:05 adamlubek

@adamlubek

did you get any exception in parsing the result?

var results = db.Collection(Rule.RULES_COLLECTION_NAME).All<JObject>().ToList();
var id = results[0].Value<int>("id");

you can get the valid json in string by results[0].ToString() but it would be better for performance if you make a http request directly for the raw result to avoid serializing.

ra0o0f avatar May 04 '16 14:05 ra0o0f

No, I don't get any exceptions.

when using results[0].ToString(), I get:

"{\r\n \"id\": 222,\r\n \"name\": \"'some other name'\",\r\n \"_id\": \"rules/586748548934\",\r\n \"_rev\": \"586751498054\",\r\n \"_key\": \"586748548934\"\r\n}"

which isn't valid json. Can I get raw json from db without specifying type? something like: db.Collection(Rule.RULES_COLLECTION_NAME).All().ToList();

adamlubek avatar May 04 '16 15:05 adamlubek

why its not valid? if you mean its Indented try result[0].ToString(Formatting.None)

ra0o0f avatar May 04 '16 15:05 ra0o0f

this works but I had to do:

working

It works now but it's not too elegant. Can you think of any better way of doing this ra0o0f?

note that when retrieving data from DB i had to use JObject coming from ArangoDB.Client namsepace and then when returning list of JObjects I had to use Nettonsoft.Json. If I used JObject from ArangDB.Client namespace everywhere then this wouldn't work.

I'm guessing here but maybe it's a case of updating Newtonsoft.Json to latest version?

adamlubek avatar May 04 '16 16:05 adamlubek

others have face his problem too, it could be solved if the client use the json.net itself instead of embeding it, i couldnt decide to remove the embeded json.net yet.

would you please tell where in your application you are consuming JObject (from json.net), that you couldnt do it with the JObject (from embeded json.net)?

ra0o0f avatar May 04 '16 16:05 ra0o0f

I expose it from ApiController as HttpResponseMessage using Ok:

capture

which without work-around I pasted in 5th comment doesn't work as it returns empty keys with empty arrays. Looks like it's a problem with version of Newtonsoft.Json that you're using in your library?

adamlubek avatar May 04 '16 21:05 adamlubek

@adamlubek the embedded json.net is now removed from the client and is using it as an nuget dependency . you can install the latest version on nuget

ra0o0f avatar Sep 06 '16 16:09 ra0o0f