Skip to content
Advertisement

Unicode JSON in Laravel blade for use in React, generating a JSON.parse problem

I have a json object in DB:

JavaScript

In the Laravel controller, I send the data to the view:

JavaScript

In the Laravel Blade, I attach the data in a div:

JavaScript

In React I get the data and save in oldData variable:

JavaScript

The problem is that I’m getting a JSON.parse error in React because that JSON print in the Laravel view DOM in the following unicode format:

JavaScript

when I parse that json in React:

JavaScript

I’m getting this error:

JavaScript

I really don’t know where is the error or what else to do.

Advertisement

Answer

You seem to double encode your JSON data: json_encode($surveyData) and then @json($surveyData) Change

JavaScript

to

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement