note 126586 added to function.json-decode

From: Date: Sat, 13 Nov 2021 16:23:31 +0000
Subject: note 126586 added to function.json-decode
Groups: php.notes 
Request: Send a blank email to php-notes+get-217199@lists.php.net to get a copy of this message
This function seems to have an undocumented return as string if the supplied json is "enveloped" as a string itself. $result1 = json_decode("{\"field1\":true,\"field2\":\"Success\",\"field3\":0,\"field4\":1.0}", true ); $result2 = json_decode('"{\"field1\":true,\"field2\":\"Success\",\"field3\":0,\"field4\":1.0}"', true ); A var_dump($result1) will show the expected result: array(4) { ["field1"]=> bool(true) ["field2"]=> string(7) "Success" ["field3"]=> int(0) ["field4"]=> float(1) } While var_dump($result2) will just result in a string instead of an array, or even null: string(58) "{"field1":true,"field2":"Success","field3":0,"field4":1.0}" This made me lose some hair recently because of a bad implementation of an external webservice we used to query. I hope it to be of any help. ---- Server IP: 45.112.84.4 Probable Submitter: 45.112.85.242 (proxied: 200.188.231.102) ---- Manual Page -- https://php.net/manual/en/function.json-decode.php Edit -- https://main.php.net/note/edit/126586 Del: integrated -- https://main.php.net/note/delete/126586/integrated Del: useless -- https://main.php.net/note/delete/126586/useless Del: bad code -- https://main.php.net/note/delete/126586/bad+code Del: spam -- https://main.php.net/note/delete/126586/spam Del: non-english -- https://main.php.net/note/delete/126586/non-english Del: in docs -- https://main.php.net/note/delete/126586/in+docs Del: other reasons-- https://main.php.net/note/delete/126586 Reject -- https://main.php.net/note/reject/126586 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#217199) next »