I am calling GetEntries and the Fields in the Items is always null. I would like the full Json as a JObject or Json string containing both the SystemProperties and Fields. I want to handle all ContentTypes generically since I many not know the content model.
var builder = new QueryBuilder<Entry>().Include(2).OrderBy(“sys.updatedAt”).Skip(skip);
var entryCollection = await _contentfulClient.GetEntries(builder);
foreach (var item in entryCollection) {
JObject entryJObject = JObject.FromObject(item);
}
You can just set the generic parameter to a JObject QueryBuilder<JObject> or dynamic QueryBuilder<dynamic> and you should be able to iterate through the JObject as you would expect.
Thanks. I’m confused that the JObject representing an entry from this call via the SDK looks “flattened” in comparison to the version one sees when using curl. I’m accustomed to seeing two properties, “sys” and “fields”. Is there a way to get the curl version back as the JObject?
The reason is I’m serializing the results to be shared with another component in my system that is expecting the entry json to look like schema returned by curl
{
“sys”: {…},
“fields”:{…}
}
Yes, that’s part of what the SDK does to make serialization more logical when you use strongly typed objects.
Currently, there’s no option to get the original structure back, unfortunately.
What you could do is to modify the JObject yourself and simply move all the properties (except the sys prop) into a property called fields and you would be back to the original structure. However, there are also other things that the SDK does, such as adding $ref and $id properties to resolve referenced content, which would also potentially interfere with your expected schema.