I am trying to use twig json_encode function but when I do this
var packageDetails = {{(packageDetails|json_encode)}};
and packageDeta
Is it simply because you are not wrapping your output in quotes?
var variable = '{{{reference}}}';
Update:
The actual answer to solve the question was adding |raw to the tag as per comments
var packageDetails = {{(packageDetails|json_encode|raw)}};