Pass array/object to JavaScript

Silverstripe Version:
Hi. I’ll try to pass an array or object to my custom JavaScript file using Requirements class like this:

    $pathToJS = ThemeResourceLoader::inst()->findThemedJavascript('js/myjs.js');
    Requirements::javascriptTemplate($pathToJS, ['ThemeDir' => Convert::array2json($arrayOfData)] );

But I have “Uncaught SyntaxError: invalid escape sequence” on frontend when reading from passing variable.

Passing array without converting it to JSON is causing SS error [Notice] Array to string conversion
Passing just string values works fine, but how to pass non-primitive types to JS?