⊗ppSpJnIS 19 of 83 menu

Handling JSON Invalidity in PHP

It happens that a string with JSON is built incorrectly. In this case, the json_decode function will return null. Let's try it in practice. Let's make invalid JSON (determine for yourself what's wrong with it):

<?php $json = '["a", "b", "c",]'; ?>

Let's try to parse this JSON:

<?php $data = json_decode($json); var_dump($data); // will output null ?>

Given a string with some JSON. Parse it into a PHP data structure. Output the parsing result or an error if parsing the JSON failed.

English
AfrikaansAzərbaycanБългарскиবাংলাБеларускаяČeštinaDanskDeutschΕλληνικάEspañolEestiSuomiFrançaisहिन्दीMagyarՀայերենIndonesiaItaliano日本語ქართულიҚазақ한국어КыргызчаLietuviųLatviešuМакедонскиMelayuမြန်မာNederlandsNorskPolskiPortuguêsRomânăРусскийසිංහලSlovenčinaSlovenščinaShqipСрпскиSrpskiSvenskaKiswahiliТоҷикӣไทยTürkmenTürkçeЎзбекOʻzbekTiếng Việt
We use cookies for website operation, analytics, and personalization. Data processing is carried out in accordance with the Privacy Policy.
accept all customize decline