How to extract and access data from JSON with PHP

0 votes

This is intended to be a general reference question and answer covering many of the never-ending "How do I access data in my JSON?" questions. It is here to handle the broad basics of decoding JSON in PHP and accessing the results.

My JSON:

{
    "type": "donut",
    "name": "Cake",
    "toppings": [
        { "id": "5002", "type": "Glazed" },
        { "id": "5006", "type": "Chocolate with Sprinkles" },
        { "id": "5004", "type": "Maple" }
    ]
}

How do I decode this in PHP and access the resulting data?

Jul 22 in PHP by narikkadan
• 11,280 points
14 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In PHP

0 votes
0 answers

How to extract img src, title and alt from html using php?

I am working on a page where ...READ MORE

Jun 3 in PHP by Kichu
• 19,040 points
56 views
0 votes
0 answers

How to filter data from a MySQL Database Table with PHP

I'm attempting to code a search box ...READ MORE

Jul 22 in PHP by narikkadan
• 11,280 points
13 views
0 votes
0 answers

How to GET data from API and show it on PHP page?

I want to use some data from ...READ MORE

Jul 31 in PHP by Kithuzzz
• 4,480 points
19 views
0 votes
1 answer

How to Validate Form Data With PHP?

Hey @kartik, The first thing we will do ...READ MORE

answered Feb 13, 2020 in PHP by Niroj
• 82,740 points
1,367 views
0 votes
1 answer

How to retrieve or obtain data from the MySQL database using PHP?

Hello kartik,  Actually there are many functions that  ...READ MORE

answered Mar 27, 2020 in PHP by Niroj
• 82,740 points
1,326 views
0 votes
1 answer

How to convert from MySQL datetime to another format with PHP?

Hello, To convert a date retrieved from MySQL ...READ MORE

answered May 19, 2020 in PHP by Niroj
• 82,740 points
962 views
0 votes
1 answer

Cant get a specific value in JSON/PHP

Convert the json-string to a php-array and ...READ MORE

answered Sep 11, 2018 in Blockchain by slayer
• 29,310 points
1,978 views
0 votes
1 answer

jsonRPCClient Error with php variables

All you have to do is change ...READ MORE

answered Sep 12, 2018 in Blockchain by digger
• 26,720 points
206 views
0 votes
0 answers

API - Convert Bitcoin Amount into USD with my Api

After apiv2.bitcoinaverage.com is not free anymore I ...READ MORE

Mar 2 in Blockchain by Aditya
• 7,300 points
245 views
0 votes
1 answer

How to get price from bitcoin to USD with api

If I'm not wrong, is this what ...READ MORE

answered Apr 7 in Blockchain by Aditya
• 7,300 points
263 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP