In parseJson() in drupal.js we test for the first character being { and, not finding it, raise an error. We need to allow the [ character too, since it's a valid JSON first character, and is sometimes generated by drupal_to_js().

CommentFileSizeAuthor
drupal-json-char.patch660 bytesnedjo
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

nedjo’s picture

Version: 4.6.6 » x.y.z

Not sure how I managed to assign this to 4.6.

drumm’s picture

Status: Reviewed & tested by the community » Needs review

I would like to see a review from Steven.

nedjo’s picture

Component: other » javascript

Recategorizing to javascript.

drob’s picture

I ran into this problem and this fix works.

Dries’s picture

Status: Needs review » Fixed

Committed to CVS HEAD.

Anonymous’s picture

Status: Fixed » Closed (fixed)
pasupathymahalingam’s picture

Version: x.y.z » 4.7.x-dev

I figured out that PHP 5.0 is introducing a \r and \n in the response..

Hence change the
/**
* All functions from here to end are temporary fixes to issues in drupal.js.
*/

/**
* Parse a JSON response.
*
* The result is either the JSON object, or an object with 'status' 0 and 'data' an error message.
*/

function parseJson(data)
{

TO

/* Trims leading and trailing spaces, \r and \n */
String.prototype.trim = function() { return this.replace(/^\s+|\s+$|^\r+|\r+$|^\n+|\n+$/, ''); };

/**
* All functions from here to end are temporary fixes to issues in drupal.js.
*/

/**
* Parse a JSON response.
*
* The result is either the JSON object, or an object with 'status' 0 and 'data' an error message.
*/

function parseJson(data)
{
data = data.trim(); // Trimming the data for space, \r and \n

Steven’s picture

You should not be getting blank lines added to your content. Most likely, you have an empty line at the end of some .php or .module file you edited.