In a json output is there a way to remove the double-quotes from the root object name and field labels? For example, views exports the following format regardless of format setting:

 {
      "items": [
           {  "label":              "John Doe",
              "type":               "Person",
               "nid":                "36"
           }
       ]
}

I need the double-quotes omitted from items, label, type and nid as shown here. Meaning only the string values should have the double-quotes.

 {
       items: [
           {   label:              "John Doe",
               type:               "Person",
               nid:                "36"
           }
       ]
}

I checked the module's files, including the theme and plugins subdirectories but nothing jumped out at me.

Also refer to this external ref:
http://simile.mit.edu/wiki/Exhibit/Creating,_Importing,_and_Managing_Data

Thank you,
George Aiello

Comments

gaiello’s picture

Bumping... as a last try to see if anyone has an idea on this before we resort to building our own PHP extracts. Thanks in advance.
-George Aiello

jimthunderbird’s picture

One way to do it will be:

$json = '
{
      "items": [
           {  "label":              "John Doe",
              "type":               "Person",
               "nid":                "36"
           }
       ]
}
';

$output = "";

$json_comps = explode("\n", $json);
array_pop($json_comps);

foreach($json_comps as $line){
  $line_comps = explode('":', $line);
  if(count($line_comps) == 2){
    $line_comps[0] = str_replace('"','',$line_comps[0]);
    $output .= $line_comps[0].":".$line_comps[1]."\n";
  }
  else{
    $output .= $line."\n"; 
  }

}

print $output;
gaiello’s picture

Thank you Jim. I have one of our developers looking at your suggestion and will report back once I know how it goes.

-George Aiello

gaiello’s picture

It turns out we made a mistake elsewhere in the destination for the json data (Sencha Touch 2) and the problem wasn't in views_datasource at all. Everything is working fine with this module for us now. My bad. Sorry.

-George Aiello

rooby’s picture

Status: Active » Fixed

This has been reported as fixed.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.