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

Mithilesh44's avatar

how to convert a json data from API to array and store in database

I am trying to fetch reviews from Google and store it in the database. first, i need to convert them into an array.

This is my json data:

"place_id" : "ChIJ4-lzBZjH5zsRLPnqEHXuEVU", "rating" : 4.9, "reference" : "CmRRAAAAxlQ6H0h6LeQkGNQO3bc8Jx8MjpLr9E0cGAD0c0RGZ-BIJPG5de5_9fuByQpjvZs7bKcEda5rmMfKfoK2VwVoJ7Pt6-4B2VNZeHB-YAp55-ZfzxA2-B69zNgP8911xIueEhDrRdKGoy1zlZjE8zXql-B8GhRP3g-cmb0YJUhF2PbYOvWc6_aYzQ", "reviews" : [ { "author_name" : "Adwait Pawaskar", "author_url" : "https://www.google.com/maps/contrib/113999417105639528965/reviews", "language" : "en", "profile_photo_url" : "https://lh5.googleusercontent.com/-woxcZ-kNOB8/AAAAAAAAAAI/AAAAAAAAAAA/AA6ZPT5CAmELoJsYT2S0C-jy0CW77la-iw/s128-c0x00000000-cc-rp-mo/photo.jpg", "rating" : 5, "relative_time_description" : "6 months ago", "text" : "101 musicals academy is a Great Class with a passionate and hardworking teacher , who knows what he is doing , always helps students , lets us learn in our own way and guides in the right direction whenever necessary. I enjoy learning music with Mithilesh", "time" : 1500523348 },

0 likes
3 replies
bobbybouwmann's avatar
Level 88

What have you tried so far?

You can use json_decode to convert the json value to a php object or array!

mdeorue's avatar

if you got the json string in a variable, as @bobbybouwmann say to you use json_decode, and magic.

$jsonArray = json_decode($jsonString);

Regards.

Mithilesh44's avatar

Yes, thanks for the heads up. I did this. but I was facing the problem when I was fetching it in an associative array.

i used $reviewdata = json_decode($jsonString,true);

giving the "TRUE" attribute solved the issue.

Please or to participate in this conversation.