Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

nafeeur10's avatar

JSON is coming with Double Quotation, How to prevent?

"{'product_id': 155, 'review_title': 'Malta Review', 'review_details': 'Malta is good', 'rating': 5 }"

I am passing data from a Nodejs project to Laravel Project. But data is coming with Double Quotation. I am doing JSON_decode() but not working.

Also did str_replace() but not working.

What is the problem?

0 likes
9 replies
bugsysha's avatar

By default, JSON is using double-quotes. I wouldn't change the default configuration cause there is nothing wrong with it.

nafeeur10's avatar

@bugsysha,

But how will I use the properties ?

Can't access directly like this $data->product_id

jlrdw's avatar

If the outter quotes are removed and you use string replace to replace the apostrophes with quotation that would be the solution, if you need it to be a variable, replace the outer quotations with apostrophes.

You're on the right track just write a helper function to handle this.

Can't access directly like this $data->product_id

You need a Json array of objects.

Edit: I don't understand is it coming In like in your question or is that after you changed it. If that's the case don't change it.

1 like
nafeeur10's avatar

@jlrdw,

Nothing is working. I can't access it.

$data = "{'product_id': 155, 'review_title': 'Malta Review', 'review_details': 'Malta is good', 'rating': 5 }"

How will I access them?

jlrdw's avatar
$data = '
{
    "type": "bold",
    "name": "something"
}';

$mydata = json_decode($data);

echo $mydata->type;

bold

Don't remove those quotation marks.

Multiple rows would be:

$mydata[0]->type;
$mydata[1]->type;
Etc
nafeeur10's avatar

Actually I am passing the properties with single quotation. It will be double quotation. Now working.

Please or to participate in this conversation.