Hey folks,
I'm trying to return a single object, however any way I approach it, it seems that the entity is wrapped in an array.
For instance, the object I want to return should look something like this:
{
"screenBackgroundColor" : "#000000",
"controlPanelColor" : "#084d98",
"progressBarColor" : "#ffffff",
"progressElapsedColor" : "#000000",
"progressBufferingColor" : "#fedb32",
"elapsedTextColor" : "#ffffff"
}
However, this module wraps my object in an array like this:
[
{
"screenBackgroundColor" : "#000000",
"controlPanelColor" : "#084d98",
"progressBarColor" : "#ffffff",
"progressElapsedColor" : "#000000",
"progressBufferingColor" : "#fedb32",
"elapsedTextColor" : "#ffffff"
}
]
This causes problems on with the player I'm using (BitDash) as the player expects an object and not an array.
I also tried with the "Object Arrays", which is close! but the entity is preceded by an object declaration of "0", like this:
{"0":{
"screenBackgroundColor":"#000000",
"controlPanelColor":"#084d98",
"progressBarColor":"#ffffff",
"progressElapsedColor":"#000000",
"progressBufferingColor":"#fedb32",
"elapsedTextColor":"#ffffff"
}}
It would be great if there was a way to output something similar to the first codeblock.
Use Case: Bitdash accepts skinning of its player using JSON. The path to the json file can be provided and to bitdash which it then parses. Example bitdash config:
...
style: {
width: '100%',
aspectratio: '16:9',
controls: playerControls,
autoHideControls: autoHideControls
}
skin : "http://mydrupalsite.com/pathto/jsonview",
cast: {
enable: true,
},
...
But since the file is returning an array, the skin configuration doesn't work... any help would be greatly appreciated.
Comment | File | Size | Author |
---|---|---|---|
#6 | add_json_single_simple_object_format-2676774-6.patch | 5.61 KB | vlad.dancer |
Comments
Comment #2
ydahiComment #3
studio-days CreditAttribution: studio-days commentedI'm having a similar problem.
As a feature request, when setting the Pager settings in the View Display to only display 1 item, the opening and closing [ ] should be removed from the output.
Is that possible?
Comment #4
anthonylindsay CreditAttribution: anthonylindsay as a volunteer commentedLet's change this to a feature request because as it stands it's not possible due to the fact that Views Datasource (and Views, I expect) needs to handle an unknown number of results. Then we can discuss the merits of the suggestion.
I'm not sure that choice of pager settings should actually change the data structure, but maybe a different setting could be squeezed in somewhere else.
Comment #5
spazfox+1 for this feature. I need it to get Drupal to feed some data to Groove using their API (https://help.groovehq.com/knowledge_base/topics/how-to-setup-the-custom-...).
Comment #6
vlad.dancerHi, folks. I've write a patch for this. Please review it.
I've added a new json format for that. Also add a form condition when this format will be available.
It returns only one object from view's rows so be careful - you should set only one item to return (via pager) to avoid unnecessary load.
See more info in README.txt inside a patch.
Comment #7
spazfoxPatch in #6 works perfectly for me. Thanks, vlad.dancer!
Comment #8
vlad.dancer@spazfox Please, change issue status to the "Reviewed and tested by the community" if you've successfully tested.
Comment #9
spazfoxComment #11
anthonylindsay CreditAttribution: anthonylindsay as a volunteer commentedCommitted to 7.x-1.x branch
http://cgit.drupalcode.org/views_datasource/commit/?h=7.x-1.x&id=e93ed74...
Comment #12
anthonylindsay CreditAttribution: anthonylindsay as a volunteer commentedclosing
Comment #13
vlad.dancerThanks, @anthonylindsay. But I see now in the dev version an odd file:
views_plugin_style_json.inc.orig
I believe you should delete it.Comment #14
anthonylindsay CreditAttribution: anthonylindsay as a volunteer commentedOops, Good catch, @vlad.dancer!
Errant file deleted.
Comment #15
iamfredrik CreditAttribution: iamfredrik commentedI need the object wrapped in an array like it was from the beginning. How do I get that feature back? I think there should be a setting so that you can choose the output.
Edit: works as designed. This was for single row output. I need it for single value field output.