json_encode(): Invalid UTF-8 sequence in argument" in file views/default/js/languages.php

I am getting hundreds of these errors in my apache log file. Anyone have a solution for me. Thanks a lot.

  • Well I seem to have fixed my problem although I had to modify the core code which I don't really like to do. Maybe someone can tell me how to extend the languages.php file using a plugin structure. Anyways here is what I changed the code in languages.php to...

    global $CONFIG;

    $language = $vars['language'];

    $value = (string)$CONFIG->translations[$language];

    if(!mb_check_encoding($value, 'UTF-8')) {
        $value = utf8_encode($value);

    echo json_encode($value);

  • i'm also seeing this in my logs.. i haven't applied this patch yet.. does anyone know any more about this? is this fix in trac somewhere?

  • Trac is down, but it sounds like one/more of the language files is not valid UTF-8. You probably want to sniff all languages/*.php files for valid UTF-8, but I don't have code on hand to do that. StackOverflow might.

    Rob's solution worries me because some strings are probably valid, and running valid UTF-8 through a function that expects ISO-8859-1 could definitely break data.

  • @Rob, the (string)$CONFIG->... just produces "Array", so this is just sending "Array" to Elgg's JS translation system. Probably not what you intended :)

  • thanks,

    i disabled all the plugins and the messages remain..
    i haven't altered the core language file.. soo..
    either there is an issue with the core language file (i haven't found a functioning tool to check the file yet), or there is an issue with my server/dbase configuration. 

    hmm.. i just notice the databse collation was set to latin1_swedish_ci for a reason i do not know..
    is there a recommended collation setting for elgg? 

  • i've set it back to utf general and converted the tables too.. 
    seems to have resolved the issue. 

  • i was mistaken..
    the cause is spam login filter plugin 1.8.2

  • What about spam login filter is causing the problem? language file?

  • i don't know presently, the errors are no longer logged when i disabled it and reappear when i re-enable it

  • There was indeed a character in the language file in that plugin.  I submitted a pull request to the author on github to correct the issue.

    Thanks Steve and ura soul for the pointers in the right direction.  the json errors were annoying.