Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Currently, the default JSON output looks like this:
{
"nodes" : [
{
"node" : {
"nid" : 1,
"title" : "title",
"field_1" : "value"
}
}
]
}
In my opinion, there's an extra, unnecessary wrapper object there (the one that wraps the "node"). AFAICT, that object will always only contain one property, the "node". However, when you update the settings for "Top-level child object" and set it to a blank value, your output looks like:
{
"nodes" : [
{
"" : {
"nid" : 1,
"title" : "title",
"field_1" : "value"
}
}
]
}
The following is ideal, more compact and doesn't lose any of the usability of the above.
{
"nodes" : [
{
"nid" : 1,
"title" : "title",
"field_1" : "value"
}
]
}
Comment | File | Size | Author |
---|---|---|---|
#2 | views_datasource-959244.patch | 1.51 KB | joshuajabbour |
#1 | views_datasource-959244.patch | 1.25 KB | joshuajabbour |
Comments
Comment #1
joshuajabbour CreditAttribution: joshuajabbour commentedThe attached patch fixes this issue. It only applies to the "simple" json data format, as I'm not too up-to-speed on Exhibit (although at first glance, it appears the current Exhibit output is actually wrong).
Comment #2
joshuajabbour CreditAttribution: joshuajabbour commentedThis updated patch also allows the "Root object name" to be left blank, giving you:
instead of:
Comment #3
joshuajabbour CreditAttribution: joshuajabbour commentedComment #4
vantuykom CreditAttribution: vantuykom commentedis there a way that somebody can give me the patched module? I'm no developer and I really don't know how to patch. But I really need the top_child_object to be not required.
regards
Comment #5
vasikesubscribe
also for "root_object"
Comment #6
rjbrown99 CreditAttribution: rjbrown99 commentedNow using this in a prod environment. It was very helpful for exporting JSON that is consumable by the iPhone. +1 for RTBC from me, speaking of the patch in #2.
Comment #7
rjbrown99 CreditAttribution: rjbrown99 commentedMoving to RTBC, I'd love to see this rolled in as I dislike managing unofficial patches in my prod source tree :)
Comment #8
Dean Reilly CreditAttribution: Dean Reilly as a volunteer commentedThis was fixed for 7.x-1.x in this issue https://www.drupal.org/node/981810
Comment #9
ZeiP CreditAttribution: ZeiP as a volunteer commentedAs Drupal 6 has been EOL for years now, closing this issue as outdated.