JS API getParents function results in syntax error


(Birdg) #1

Hi,  
I am using the JS API on 4.16.0 to get the parents of an asset (using the getParents method). I am specifically looking for parents of a certain type and with a certain link value so sometimes there are none.

 

When the ajax call comes back and http.responseText is about to be returned, it is sent through jsonToObj first for formatting purposes.

 

However, if the asset has no parents then http.responseText is empty and so the JSON.parse method fails with a syntax error ("Unexpected end of input").

 

The existing function is below (with additional comment from me).

 

Does anyone know whether this has been fixed in a later version?

 

Thanks,

 

Graham

/**
* Convert a JSON string to object
*/
function jsonToObj(json)
{
  // Make the conversion
  if (typeof(JSON) !== 'undefined') {
    // Needs a check for empty string here!
    return JSON.parse(json);
  }// end if

// Don’t worry, even the creator of JSON says eval is ok here
return eval(’(’ + json + ‘)’);

}// end jsonToObj


(Birdg) #2

I raised this as a bug: http://bugs.matrix.squiz.net/view_bug.php?bug_id=6820


(Ashish Karelia) #3

This is is resolved on bug #6750 JS API getParents doesn't return the 1st parent, throws Unexpected end of input error.


(Birdg) #4

Hi Ashish,

Thanks for your reply. I did see that bug report but it sounded like a different issue with the same result. Does the fix cover both cases?


Thanks,


Graham


(Ashish Karelia) #5

Hi Graham,

The bug I mentioned, yes it fixes 2 on the patch.

 

Ash