Pass array/object to JavaScript

<%- if @topic_view.topic.tags.present? %>
<%= t 'js.tagging.tags' %>: <%- @topic_view.topic.tags.each do |t| %> <%= t %> <%- end %>
<% end %>

Silverstripe Version:
4.*
Question:
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?