Question

I have a big doubt about the JSON format the Services module (for Drupal 6) generates.

When I view the XML, all is OK.

<result is_array="true">
 <item>
  <nid>9</nid>
  <vid>9</vid>
  <type>producto</type>
 </item>
</result>

When I view the JSON, I see this:

[
 {
  "nid": "9",
  "vid": "9",
  "type": "producto",
 }
]

What I really is something like this:

[
 {
  "item":{
    "nid": "9",
    "vid": "9",
    "type": "producto",
  }
 }
]

How do I do this? Is there any configuration in the Services module that I can use to change the output, or do I need writing code?
I know the function to render JSON output.

Was it helpful?

Solution

You should implement hook_services_request_postprocess_alter().

OTHER TIPS

As I mentioned before, hook_services_request_postprocess_alter will not provide you what type of data it's processing. It means that your code must be really hacky to catch exactly type of data you need.

You better create your own formatter with hook_rest_server_response_formatters_alter, and use it to render data.

Licensed under: CC-BY-SA with attribution
Not affiliated with drupal.stackexchange
scroll top