The problem
Your following code
<script>
var testvar = "{{\Session::get('test')}}";
var data = JSON.parse(testvar);
</script>
would be interpreted as:
<script>
var testvar = {'test1':'123','test2':'456'};
var data = JSON.parse(testvar);
</script>
{'test1':'123','test2':'456'} is invalid JSON, as you need to use double quotes instead of single quotes.
So you need:
Session::put('test', '{"test1":"123","test2":"456"}');
But this creates another problem.
Laravel auto escapes HTML for security reasons to avoid XSS attacks.
This means the above is now interpreted as :
<script>
var testvar = {"test1":"123","test2":"456"}"
var data = JSON.parse(testvar);
</script>
If you are sure the data you are storing is safe, you can use raw tags like so, and avoid using JSON.parse (so we don't need to re-escape any of the quotes again) like so:
<script>
var testvar = {!! Session::get('test') !!};
</script>
This will then output the HTML:
<script>
var testvar = {"test1":"123", "test2":"456"};
</script>
A better solution
A better way is to store your data as an array in the PHP session:
Session::put('test', [
'test1' => '123',
'test2' => '456'
]);
Then you could just do:
<script>
var testvar = @json(Session::get('test'));
</script>
This is explained here:
https://laravel.com/docs/5.7/blade#displaying-data
Side Note
As a side note, consider passing a variable into blade to avoid doing logic in your views like so:
return view('your-view-name', [
'testvar' => Session::get('test'),
]);
Then you could just do:
<script>
var testvar = @json($testvar);
</script>
Sessionin a blade? You need to pass these values as parameters to the blade, respecting MVC.