arangoclient.net
arangoclient.net copied to clipboard
IDocumentCollection.Collection returns invalid JSON when using JObject as a type
Hi,
I have following content stored in a collection:
Then, I do
db.Collection(Rule.RULES_COLLECTION_NAME) .All<JObject>() .ToList()
(JObject comes from ArangoDB.Client.Common.Newtonsoft.Json.Linq)
which returns:
which is not a valid JSON (see double curly braces surrounding each object). Am I missing something or is this a bug?
@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.
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();
why its not valid? if you mean its Indented try result[0].ToString(Formatting.None)
this works but I had to do:
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?
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)?
I expose it from ApiController as HttpResponseMessage using Ok:
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 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