JSON Decode PHP

I am creating a website for a friend's art project. It needs to be done by 9PM. I have done most of the front end work, and I am calling a Bing API that is returning JSON.

I don't know how to target and retrieve the data I need, this JSON is more complicated than other JSON I've worked with.

Is there a way I can view the variable and figure out how to call the data?


The JSON is posted below.

{"_type": "SearchResponse", "queryContext": {"originalQuery": "Microsoft Cognitive Services"}, "webPages": {"webSearchUrl": "https:\/\/www.bing.com\/search?q=Microsoft+Cognitive+Services", "totalEstimatedMatches": 19200000, "value": [{"id": "https:\/\/api.cognitive.microsoft.com\/api\/v7\/#WebPages.0", "name": "Microsoft Cognitive Services", "url": "https:\/\/www.microsoft.com\/cognitive-services", "isFamilyFriendly": true, "displayUrl": "https:\/\/www.microsoft.com\/cognitive-services", "snippet": "Knock down barriers between you and your ideas. Enable natural and contextual interaction with tools that augment users' experiences via the power of machine-based AI. Plug them in and bring your ideas to life.", "deepLinks": [{"name": "Face API", "url": "https:\/\/azure.microsoft.com\/en-us\/services\/cognitive-services\/face\/", "snippet": "Build facial recognition software into your applications with the Face API from …"}, {"name": "Text Analytics", "url": "https:\/\/azure.microsoft.com\/en-us\/services\/cognitive-services\/text-analytics\/", "snippet": "Turn unstructured text into meaningful insights with the Text Analytics API …"}, {"name": "Computer Vision API", "url": "https:\/\/azure.microsoft.com\/en-us\/services\/cognitive-services\/computer-vision\/", "snippet": "Analyze images and extract the data you need with the Computer Vision API …"}, {"name": "Emotion", "url": "https:\/\/azure.microsoft.com\/en-us\/services\/cognitive-services\/emotion\/", "snippet": "Build smarter applications with the Emotion API from Microsoft Azure. Recognize facial emotions in images based on universal facial expressions."}, {"name": "Bing Speech API", "url": "https:\/\/azure.microsoft.com\/en-us\/services\/cognitive-services\/speech\/", "snippet": "Build speech recognition software into your applications with the Bing …"}, {"name": "Get Started for Free", "url": "https:\/\/azure.microsoft.com\/en-us\/services\/cognitive-services\/?cdn=disable", "snippet": "Add vision, speech, language and knowledge capabilities to your apps with artificial intelligence APIs from Cognitive Services. Explore our APIs today."}]}, {"id": "https:\/\/api.cognitive.microsoft.com\/api\/v7\/#WebPages.1", "name": "Cognitive Service Try experience | Microsoft Azure", "url": "https:\/\/azure.microsoft.com\/en-us\/try\/cognitive-services\/", "isFamilyFriendly": true, "displayUrl": "https:\/\/azure.microsoft.com\/en-us\/try\/cognitive-services", "snippet": "Microsoft Cognitive Services Try experience lets you build apps with powerful algorithms using just a few lines of code through a 30 day trial.", "dateLastCrawled": "2018-03-07T03:08:00.0000000Z"}, {"id": "https:\/\/api.cognitive.microsoft.com\/api\/v7\/#WebPages.2", "name": "Microsoft Trust Center | Microsoft Cognitive Services", "url": "https:\/\/www.microsoft.com\/en-us\/trustcenter\/cloudservices\/cognitiveservices", "isFamilyFriendly": true, "displayUrl": "https:\/\/www.microsoft.com\/...\/cloudservices\/cognitiveservices", "snippet": "Microsoft Cognitive Services is a collection of intelligent APIs that allow systems to understand and interpret people’s needs by using natural methods of ...", "dateLastCrawled": "2018-03-08T02:25:00.0000000Z"}, {"id": "https:\/\/api.cognitive.microsoft.com\/api\/v7\/#WebPages.3", "name": "Microsoft Cognitive Services - customers.microsoft.com", "url": "https:\/\/customers.microsoft.com\/en-us\/search?sq=%22Microsoft%20Cognitive%20Services%22&ff=&p=0&so=story_publish_date%20desc", "isFamilyFriendly": true, "displayUrl": "https:\/\/customers.microsoft.com\/en-us\/search?sq=\"Microsoft...", "snippet": "Microsoft customer stories. See how Microsoft tools help companies run their business.", "dateLastCrawled": "2018-03-07T20:46:00.0000000Z"}, {"id": "https:\/\/api.cognitive.microsoft.com\/api\/v7\/#WebPages.4", "name": "What is Microsoft Cognitive Services? | Microsoft Docs", "url": "https:\/\/docs.microsoft.com\/en-us\/azure\/cognitive-services\/Welcome", "isFamilyFriendly": true, "displayUrl": "https:\/\/docs.microsoft.com\/en-us\/azure\/cognitive-services\/Welcome", "snippet": "Microsoft Cognitive Services is a set of APIs, SDKs, and services that you can use with Microsoft Azure that make applications more intelligent, engaging, and ...", "dateLastCrawled": "2018-03-01T19:06:00.0000000Z", "searchTags": [{"name": "search.ms_sitename", "content": "\"Docs\"; docs"}, {"name": "search.ms_docsetname", "content": "\"azure-documents\"; azure; documents"}, {"name": "search.ms_product", "content": "\"Azure\"; azure"}]}, {"id": "https:\/\/api.cognitive.microsoft.com\/api\/v7\/#WebPages.5", "name": "Microsoft Enterprise Services - Microsoft Enterprise", "url": "https:\/\/enterprise.microsoft.com\/en-us\/services\/", "isFamilyFriendly": true, "displayUrl": "https:\/\/enterprise.microsoft.com\/en-us\/services", "snippet": "Microsoft Enterprise Services digital advisors, engineers, consultants, and support professionals help you implement and adopt Microsoft products, services, software ...", "dateLastCrawled": "2018-03-08T07:34:00.0000000Z"}, {"id": "https:\/\/api.cognitive.microsoft.com\/api\/v7\/#WebPages.6", "name": "Face API Service overview - Microsoft Cognitive Services ...", "url": "https:\/\/docs.microsoft.com\/en-us\/azure\/cognitive-services\/face\/overview", "isFamilyFriendly": true, "displayUrl": "https:\/\/docs.microsoft.com\/en-us\/azure\/cognitive-services\/face\/...", "snippet": "The glossary explains terms that you might encounter as you work with the Face API Service.", "dateLastCrawled": "2018-03-10T11:07:00.0000000Z", "searchTags": [{"name": "search.ms_sitename", "content": "\"Docs\"; docs"}, {"name": "search.ms_docsetname", "content": "\"azure-documents\"; azure; documents"}, {"name": "search.ms_product", "content": "\"Azure\"; azure"}]}, {"id": "https:\/\/api.cognitive.microsoft.com\/api\/v7\/#WebPages.7", "name": "Microsoft Cognitive Services push gains momentum - The AI Blog", "url": "https:\/\/blogs.microsoft.com\/ai\/microsoft-cognitive-services-push-gains-momentum\/", "isFamilyFriendly": true, "displayUrl": "https:\/\/blogs.microsoft.com\/ai\/microsoft-cognitive-services-push...", "snippet": " The machine-learned smarts that enable Microsoft’s Skype Translator, Bing and Cortana to accomplish tasks such as translating conversations ...", "dateLastCrawled": "2018-02-25T15:59:00.0000000Z"}]}, "relatedSearches": {"id": "https:\/\/api.cognitive.microsoft.com\/api\/v7\/#RelatedSearches", "value": [{"text": "microsoft cognitive services demo", "displayText": "microsoft cognitive services demo", "webSearchUrl": "https:\/\/www.bing.com\/search?q=microsoft+cognitive+services+demo"}, {"text": "microsoft cognitive services samples", "displayText": "microsoft cognitive services samples", "webSearchUrl": "https:\/\/www.bing.com\/search?q=microsoft+cognitive+services+samples"}, {"text": "microsoft cognitive services youtube", "displayText": "microsoft cognitive services youtube", "webSearchUrl": "https:\/\/www.bing.com\/search?q=microsoft+cognitive+services+youtube"}, {"text": "bing cognitive services", "displayText": "bing cognitive services", "webSearchUrl": "https:\/\/www.bing.com\/search?q=bing+cognitive+services"}, {"text": "microsoft cognitive services kiosk", "displayText": "microsoft cognitive services kiosk", "webSearchUrl": "https:\/\/www.bing.com\/search?q=microsoft+cognitive+services+kiosk"}, {"text": "microsoft cognitive services text analytics", "displayText": "microsoft cognitive services text analytics", "webSearchUrl": "https:\/\/www.bing.com\/search?q=microsoft+cognitive+services+text+analytics"}, {"text": "web search cognitive services", "displayText": "web search cognitive services", "webSearchUrl": "https:\/\/www.bing.com\/search?q=web+search+cognitive+services"}, {"text": "azure cognitive services demo", "displayText": "azure cognitive services demo", "webSearchUrl": "https:\/\/www.bing.com\/search?q=azure+cognitive+services+demo"}]}, "rankingResponse": {"mainline": {"items": [{"answerType": "WebPages", "resultIndex": 0, "value": {"id": "https:\/\/api.cognitive.microsoft.com\/api\/v7\/#WebPages.0"}}, {"answerType": "WebPages", "resultIndex": 1, "value": {"id": "https:\/\/api.cognitive.microsoft.com\/api\/v7\/#WebPages.1"}}, {"answerType": "WebPages", "resultIndex": 2, "value": {"id": "https:\/\/api.cognitive.microsoft.com\/api\/v7\/#WebPages.2"}}, {"answerType": "WebPages", "resultIndex": 3, "value": {"id": "https:\/\/api.cognitive.microsoft.com\/api\/v7\/#WebPages.3"}}, {"answerType": "WebPages", "resultIndex": 4, "value": {"id": "https:\/\/api.cognitive.microsoft.com\/api\/v7\/#WebPages.4"}}, {"answerType": "WebPages", "resultIndex": 5, "value": {"id": "https:\/\/api.cognitive.microsoft.com\/api\/v7\/#WebPages.5"}}, {"answerType": "WebPages", "resultIndex": 6, "value": {"id": "https:\/\/api.cognitive.microsoft.com\/api\/v7\/#WebPages.6"}}, {"answerType": "WebPages", "resultIndex": 7, "value": {"id": "https:\/\/api.cognitive.microsoft.com\/api\/v7\/#WebPages.7"}}]}, "sidebar": {"items": [{"answerType": "RelatedSearches", "value": {"id": "https:\/\/api.cognitive.microsoft.com\/api\/v7\/#RelatedSearches"}}]}}}

Open in new window

burnedfacelessAsked:
Who is Participating?
 
gr8gonzoConnect With a Mentor ConsultantCommented:
If you ever want to see a nicely-formatted JSON array, just create a blank PHP page with this:
echo "<pre>";
<?php print_r(json_decode("JSON goes here", true)); ?> 
echo "</pre>";

Open in new window


...and view it in your browser. You should see something like this:
Array
(
    [_type] => SearchResponse
    [queryContext] => Array
        (
            [originalQuery] => Microsoft Cognitive Services
        )

    [webPages] => Array
        (
            [webSearchUrl] => https://www.bing.com/search?q=Microsoft+Cognitive+Services
            [totalEstimatedMatches] => 19200000
            [value] => Array
                (
                    [0] => Array
                        (
                            [id] => https://api.cognitive.microsoft.com/api/v7/#WebPages.0
                            [name] => Microsoft Cognitive Services
                            [url] => https://www.microsoft.com/cognitive-services
                            [isFamilyFriendly] => 1
                            [displayUrl] => https://www.microsoft.com/cognitive-services
                            [snippet] => Knock down barriers between you and your ideas. Enable natural and contextual interaction with tools that augment users' experiences via the power of machine-based AI. Plug them in and bring your ideas to life.
                            [deepLinks] => Array
                                (
                                    [0] => Array
                                        (
                                            [name] => Face API
                                            [url] => https://azure.microsoft.com/en-us/services/cognitive-services/face/
                                            [snippet] => Build facial recognition software into your applications with the Face API from …
                                        )

                                    [1] => Array
                                        (
                                            [name] => Text Analytics
                                            [url] => https://azure.microsoft.com/en-us/services/cognitive-services/text-analytics/
                                            [snippet] => Turn unstructured text into meaningful insights with the Text Analytics API …
                                        )

                                    [2] => Array
                                        (
                                            [name] => Computer Vision API
                                            [url] => https://azure.microsoft.com/en-us/services/cognitive-services/computer-vision/
                                            [snippet] => Analyze images and extract the data you need with the Computer Vision API …
                                        )

                                    [3] => Array
                                        (
                                            [name] => Emotion
                                            [url] => https://azure.microsoft.com/en-us/services/cognitive-services/emotion/
                                            [snippet] => Build smarter applications with the Emotion API from Microsoft Azure. Recognize facial emotions in images based on universal facial expressions.
                                        )

                                    [4] => Array
                                        (
                                            [name] => Bing Speech API
                                            [url] => https://azure.microsoft.com/en-us/services/cognitive-services/speech/
                                            [snippet] => Build speech recognition software into your applications with the Bing …
                                        )

                                    [5] => Array
                                        (
                                            [name] => Get Started for Free
                                            [url] => https://azure.microsoft.com/en-us/services/cognitive-services/?cdn=disable
                                            [snippet] => Add vision, speech, language and knowledge capabilities to your apps with artificial intelligence APIs from Cognitive Services. Explore our APIs today.
                                        )

                                )

                        )

                    [1] => Array
                        (
                            [id] => https://api.cognitive.microsoft.com/api/v7/#WebPages.1
                            [name] => Cognitive Service Try experience | Microsoft Azure
                            [url] => https://azure.microsoft.com/en-us/try/cognitive-services/
                            [isFamilyFriendly] => 1
                            [displayUrl] => https://azure.microsoft.com/en-us/try/cognitive-services
                            [snippet] => Microsoft Cognitive Services Try experience lets you build apps with powerful algorithms using just a few lines of code through a 30 day trial.
                            [dateLastCrawled] => 2018-03-07T03:08:00.0000000Z
                        )

                    [2] => Array
                        (
                            [id] => https://api.cognitive.microsoft.com/api/v7/#WebPages.2
                            [name] => Microsoft Trust Center | Microsoft Cognitive Services
                            [url] => https://www.microsoft.com/en-us/trustcenter/cloudservices/cognitiveservices
                            [isFamilyFriendly] => 1
                            [displayUrl] => https://www.microsoft.com/.../cloudservices/cognitiveservices
                            [snippet] => Microsoft Cognitive Services is a collection of intelligent APIs that allow systems to understand and interpret people’s needs by using natural methods of ...
                            [dateLastCrawled] => 2018-03-08T02:25:00.0000000Z
                        )

                    [3] => Array
                        (
                            [id] => https://api.cognitive.microsoft.com/api/v7/#WebPages.3
                            [name] => Microsoft Cognitive Services - customers.microsoft.com
                            [url] => https://customers.microsoft.com/en-us/search?sq=%22Microsoft%20Cognitive%20Services%22&ff=&p=0&so=story_publish_date%20desc
                            [isFamilyFriendly] => 1
                            [displayUrl] => https://customers.microsoft.com/en-us/search?sq="Microsoft...
                            [snippet] => Microsoft customer stories. See how Microsoft tools help companies run their business.
                            [dateLastCrawled] => 2018-03-07T20:46:00.0000000Z
                        )

                    [4] => Array
                        (
                            [id] => https://api.cognitive.microsoft.com/api/v7/#WebPages.4
                            [name] => What is Microsoft Cognitive Services? | Microsoft Docs
                            [url] => https://docs.microsoft.com/en-us/azure/cognitive-services/Welcome
                            [isFamilyFriendly] => 1
                            [displayUrl] => https://docs.microsoft.com/en-us/azure/cognitive-services/Welcome
                            [snippet] => Microsoft Cognitive Services is a set of APIs, SDKs, and services that you can use with Microsoft Azure that make applications more intelligent, engaging, and ...
                            [dateLastCrawled] => 2018-03-01T19:06:00.0000000Z
                            [searchTags] => Array
                                (
                                    [0] => Array
                                        (
                                            [name] => search.ms_sitename
                                            [content] => "Docs"; docs
                                        )

                                    [1] => Array
                                        (
                                            [name] => search.ms_docsetname
                                            [content] => "azure-documents"; azure; documents
                                        )

                                    [2] => Array
                                        (
                                            [name] => search.ms_product
                                            [content] => "Azure"; azure
                                        )

                                )

                        )

                    [5] => Array
                        (
                            [id] => https://api.cognitive.microsoft.com/api/v7/#WebPages.5
                            [name] => Microsoft Enterprise Services - Microsoft Enterprise
                            [url] => https://enterprise.microsoft.com/en-us/services/
                            [isFamilyFriendly] => 1
                            [displayUrl] => https://enterprise.microsoft.com/en-us/services
                            [snippet] => Microsoft Enterprise Services digital advisors, engineers, consultants, and support professionals help you implement and adopt Microsoft products, services, software ...
                            [dateLastCrawled] => 2018-03-08T07:34:00.0000000Z
                        )

                    [6] => Array
                        (
                            [id] => https://api.cognitive.microsoft.com/api/v7/#WebPages.6
                            [name] => Face API Service overview - Microsoft Cognitive Services ...
                            [url] => https://docs.microsoft.com/en-us/azure/cognitive-services/face/overview
                            [isFamilyFriendly] => 1
                            [displayUrl] => https://docs.microsoft.com/en-us/azure/cognitive-services/face/...
                            [snippet] => The glossary explains terms that you might encounter as you work with the Face API Service.
                            [dateLastCrawled] => 2018-03-10T11:07:00.0000000Z
                            [searchTags] => Array
                                (
                                    [0] => Array
                                        (
                                            [name] => search.ms_sitename
                                            [content] => "Docs"; docs
                                        )

                                    [1] => Array
                                        (
                                            [name] => search.ms_docsetname
                                            [content] => "azure-documents"; azure; documents
                                        )

                                    [2] => Array
                                        (
                                            [name] => search.ms_product
                                            [content] => "Azure"; azure
                                        )

                                )

                        )

                    [7] => Array
                        (
                            [id] => https://api.cognitive.microsoft.com/api/v7/#WebPages.7
                            [name] => Microsoft Cognitive Services push gains momentum - The AI Blog
                            [url] => https://blogs.microsoft.com/ai/microsoft-cognitive-services-push-gains-momentum/
                            [isFamilyFriendly] => 1
                            [displayUrl] => https://blogs.microsoft.com/ai/microsoft-cognitive-services-push...
                            [snippet] =>  The machine-learned smarts that enable Microsoft’s Skype Translator, Bing and Cortana to accomplish tasks such as translating conversations ...
                            [dateLastCrawled] => 2018-02-25T15:59:00.0000000Z
                        )

                )

        )

    [relatedSearches] => Array
        (
            [id] => https://api.cognitive.microsoft.com/api/v7/#RelatedSearches
            [value] => Array
                (
                    [0] => Array
                        (
                            [text] => microsoft cognitive services demo
                            [displayText] => microsoft cognitive services demo
                            [webSearchUrl] => https://www.bing.com/search?q=microsoft+cognitive+services+demo
                        )

                    [1] => Array
                        (
                            [text] => microsoft cognitive services samples
                            [displayText] => microsoft cognitive services samples
                            [webSearchUrl] => https://www.bing.com/search?q=microsoft+cognitive+services+samples
                        )

                    [2] => Array
                        (
                            [text] => microsoft cognitive services youtube
                            [displayText] => microsoft cognitive services youtube
                            [webSearchUrl] => https://www.bing.com/search?q=microsoft+cognitive+services+youtube
                        )

                    [3] => Array
                        (
                            [text] => bing cognitive services
                            [displayText] => bing cognitive services
                            [webSearchUrl] => https://www.bing.com/search?q=bing+cognitive+services
                        )

                    [4] => Array
                        (
                            [text] => microsoft cognitive services kiosk
                            [displayText] => microsoft cognitive services kiosk
                            [webSearchUrl] => https://www.bing.com/search?q=microsoft+cognitive+services+kiosk
                        )

                    [5] => Array
                        (
                            [text] => microsoft cognitive services text analytics
                            [displayText] => microsoft cognitive services text analytics
                            [webSearchUrl] => https://www.bing.com/search?q=microsoft+cognitive+services+text+analytics
                        )

                    [6] => Array
                        (
                            [text] => web search cognitive services
                            [displayText] => web search cognitive services
                            [webSearchUrl] => https://www.bing.com/search?q=web+search+cognitive+services
                        )

                    [7] => Array
                        (
                            [text] => azure cognitive services demo
                            [displayText] => azure cognitive services demo
                            [webSearchUrl] => https://www.bing.com/search?q=azure+cognitive+services+demo
                        )

                )

        )

    [rankingResponse] => Array
        (
            [mainline] => Array
                (
                    [items] => Array
                        (
                            [0] => Array
                                (
                                    [answerType] => WebPages
                                    [resultIndex] => 0
                                    [value] => Array
                                        (
                                            [id] => https://api.cognitive.microsoft.com/api/v7/#WebPages.0
                                        )

                                )

                            [1] => Array
                                (
                                    [answerType] => WebPages
                                    [resultIndex] => 1
                                    [value] => Array
                                        (
                                            [id] => https://api.cognitive.microsoft.com/api/v7/#WebPages.1
                                        )

                                )

                            [2] => Array
                                (
                                    [answerType] => WebPages
                                    [resultIndex] => 2
                                    [value] => Array
                                        (
                                            [id] => https://api.cognitive.microsoft.com/api/v7/#WebPages.2
                                        )

                                )

                            [3] => Array
                                (
                                    [answerType] => WebPages
                                    [resultIndex] => 3
                                    [value] => Array
                                        (
                                            [id] => https://api.cognitive.microsoft.com/api/v7/#WebPages.3
                                        )

                                )

                            [4] => Array
                                (
                                    [answerType] => WebPages
                                    [resultIndex] => 4
                                    [value] => Array
                                        (
                                            [id] => https://api.cognitive.microsoft.com/api/v7/#WebPages.4
                                        )

                                )

                            [5] => Array
                                (
                                    [answerType] => WebPages
                                    [resultIndex] => 5
                                    [value] => Array
                                        (
                                            [id] => https://api.cognitive.microsoft.com/api/v7/#WebPages.5
                                        )

                                )

                            [6] => Array
                                (
                                    [answerType] => WebPages
                                    [resultIndex] => 6
                                    [value] => Array
                                        (
                                            [id] => https://api.cognitive.microsoft.com/api/v7/#WebPages.6
                                        )

                                )

                            [7] => Array
                                (
                                    [answerType] => WebPages
                                    [resultIndex] => 7
                                    [value] => Array
                                        (
                                            [id] => https://api.cognitive.microsoft.com/api/v7/#WebPages.7
                                        )

                                )

                        )

                )

            [sidebar] => Array
                (
                    [items] => Array
                        (
                            [0] => Array
                                (
                                    [answerType] => RelatedSearches
                                    [value] => Array
                                        (
                                            [id] => https://api.cognitive.microsoft.com/api/v7/#RelatedSearches
                                        )

                                )

                        )

                )

        )

)

Open in new window


That said, I don't know what value you're specifically after, but I hope this is enough to point you in the right direction.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.